Class ForClauseIterator

All Implemented Interfaces:
Serializable, DataFrameRuntimePlan<FlworTuple>, LocalRuntimePlan<FlworTuple>, NativeQueryRuntimePlan

public class ForClauseIterator extends TupleRuntimePlan implements DataFrameRuntimePlan<FlworTuple>
See Also:
  • Constructor Details

  • Method Details

    • createNativeCursor

      public Cursor<FlworTuple> createNativeCursor(DynamicContext context)
      Description copied from interface: LocalRuntimePlan
      Creates an independent cursor for one native local evaluation.
      Specified by:
      createNativeCursor in interface LocalRuntimePlan<FlworTuple>
      Specified by:
      createNativeCursor in class TupleRuntimePlan
      Parameters:
      context - the dynamic context for that evaluation
      Returns:
      an unopened cursor
    • createNativeDataFrame

      public FlworDataFrame createNativeDataFrame(DynamicContext context)
      Description copied from interface: DataFrameRuntimePlan
      Builds the DataFrame for one evaluation.
      Specified by:
      createNativeDataFrame in interface DataFrameRuntimePlan<FlworTuple>
      Parameters:
      context - the dynamic context for that evaluation
      Returns:
      the resulting DataFrame
    • getDataFrameStartingClause

      public static FlworDataFrame getDataFrameStartingClause(ItemRuntimePlan iterator, Name variableName, Name positionalVariableName, boolean allowingEmpty, DynamicContext context, Map<Name,DynamicContext.VariableDependency> outputDependencies)
      Starting clause and the expression is parallelizable.
      Parameters:
      iterator - the expression iterator
      variableName - the name of the for variable
      positionalVariableName - the name of the positional variable (or null if none)
      allowingEmpty - whether the allowing empty option is present
      context - the dynamic context.
      outputDependencies - the desired project.
      Returns:
      the resulting DataFrame.
    • getDynamicContextVariableDependencies

      public Map<Name,DynamicContext.VariableDependency> getDynamicContextVariableDependencies()
      Description copied from class: TupleRuntimePlan
      Variable dependencies are variables that MUST be provided by the parent clause in the dynamic context for successful execution of this clause. These variables are: 1. All variables that the expression of the clause depends on (recursive call of getVariableDependencies on the expression) 2. Except those variables bound in the current FLWOR (obtained from the auxiliary method getVariablesBoundInCurrentFLWORExpression), because those are provided in the Tuples 3. Plus (recursively calling getVariableDependencies) all the Variable Dependencies of the child clause if it exists.
      Overrides:
      getDynamicContextVariableDependencies in class TupleRuntimePlan
      Returns:
      a map of variable names to dependencies (FULL, COUNT, ...) that this clause needs to obtain from the dynamic context.
    • getOutputTupleVariableNames

      public Set<Name> getOutputTupleVariableNames()
      Description copied from class: TupleRuntimePlan
      Returns the output tuple variable names. These variables can be removed from the dependencies of expressions in ascendent (subsequent) clauses, because their values are provided in the tuples rather than the dynamic context object.
      Overrides:
      getOutputTupleVariableNames in class TupleRuntimePlan
      Returns:
      the set of variable names that are bound by descendant clauses.
    • print

      public void print(StringBuilder buffer, int indent)
      Overrides:
      print in class TupleRuntimePlan
    • getInputTupleVariableDependencies

      public Map<Name,DynamicContext.VariableDependency> getInputTupleVariableDependencies(Map<Name,DynamicContext.VariableDependency> parentProjection)
      Description copied from class: TupleRuntimePlan
      Builds the DataFrame projection that this clause needs to receive from its child clause. The intent is that the result of this method is forwarded to the child clause in getDataFrame() so it can optimize some values away. Invariant: all keys in getInputTupleVariableDependencies(...) MUST be output tuple variables, i.e., appear in this.child.getOutputTupleVariableNames()
      Specified by:
      getInputTupleVariableDependencies in class TupleRuntimePlan
      Parameters:
      parentProjection - the projection needed by the parent clause.
      Returns:
      the projection needed by this clause.
    • tryNativeQuery

      public static FlworDataFrame tryNativeQuery(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataFrame, Name newVariableName, Name positionalVariableName, boolean allowingEmpty, ItemRuntimePlan iterator, List<FlworDataFrameColumn> allColumns, org.apache.spark.sql.types.StructType inputSchema, DynamicContext context)
      Try to generate the native query for the for clause and run it, if successful return the resulting dataframe, otherwise it returns null
      Parameters:
      dataFrame - input dataframe for the query
      newVariableName - name of the new bound variable
      positionalVariableName - name of the positional variable (or null if absent)
      allowingEmpty - boolean signaling allowing empty flag in expression
      iterator - for variable assignment expression iterator
      allColumns - other columns required in following clauses
      inputSchema - input schema of the dataframe
      context - current dynamic context of the dataframe
      Returns:
      resulting dataframe of the for clause if successful, null otherwise
    • containsClause

      public boolean containsClause(FLWOR_CLAUSES kind)
      Description copied from class: TupleRuntimePlan
      Says whether or not the clause and its descendants include a clause of the specified kind.
      Specified by:
      containsClause in class TupleRuntimePlan
      Parameters:
      kind - the kind of clause to test for.
      Returns:
      true if there is one. False otherwise.
    • registerForClauseUDF

      public static void registerForClauseUDF(org.apache.spark.sql.Dataset<org.apache.spark.sql.Row> dataFrame, ItemRuntimePlan newVariableExpression, DynamicContext context, org.apache.spark.sql.types.StructType inputSchema, List<FlworDataFrameColumn> UDFcolumns, SequenceType sequenceType)
    • isSparkJobNeeded

      public boolean isSparkJobNeeded()
      Says whether this expression evaluation triggers a Spark job.
      Specified by:
      isSparkJobNeeded in class TupleRuntimePlan
      Returns:
      true if the execution triggers a Spark, false otherwise, null if undetermined yet.
    • generateNativeQuery

      public NativeClauseContext generateNativeQuery(NativeClauseContext nativeClauseContext)
      This function generate (if possible) a native spark-sql query that maps the inner working of the iterator
      Specified by:
      generateNativeQuery in interface NativeQueryRuntimePlan
      Overrides:
      generateNativeQuery in class TupleRuntimePlan
      Parameters:
      nativeClauseContext - context information to generate the native query
      Returns:
      a native clause context with the spark-sql native query to get an equivalent result of the iterator, or [NativeClauseContext.NoNativeQuery] if it is not possible