felix.dstruct
Class DataMovementOperator

java.lang.Object
  extended by felix.dstruct.DataMovementOperator

public class DataMovementOperator
extends java.lang.Object

A Data Movement Operator (DMO) is a bridge from physical database objects (e.g., view, relational table etc.) to logical requirements of the data. A statistical operator (e.g., CRF, Coref etc.) only knows the logic of DMO instead of the physical execution plan. The physical execution plan of the DMO is instantiated by the Optimizer. The logic definition of the DMO is instantiated by corresponding statistical operators.

Author:
Ce Zhang

Nested Class Summary
 class DataMovementOperator.QuerySet
          A collection containing 1) a set of datalog rules; 2) a conjunctive query or prepared statement.
 
Field Summary
 java.util.ArrayList<java.lang.String> additionalSelList
          Part of the schema of the output of this DMO, which is additionally assigned (i.e., may not be founded in the conjunctive query or prepared statement in logicQueryPlan).
 boolean allowOptimization
          Whether this DMO allowing optimizations from the optimizer.
 boolean asView
          Whether the output (if any) of this DMO should be regarded as view or materialized table.
 tuffy.db.RDB db
          RDB object on which this DMO works on.
 java.util.ArrayList<java.lang.String> finalSelList
          The schema for the output of this DMO.
static int globalID
          Counter for DMO ID.
 boolean hasKnownFetchingOrder
          Whether this DMO allows pre-fetching.
 boolean hasPrepared
          Whether prepare() method has been invoked.
 boolean isIntermediaDMO
          Whether this DMO can be used as view/table by other DMOs.
 DataMovementOperator.QuerySet logicQueryPlan
          Conjunctive query or prepared statement acting as the *logic* description of this DMO.
 java.lang.String name
          Name of table/view generated by this DMO.
 boolean needIndex
          Do we need to build index for this DMO's output/intermediate results?
 java.util.ArrayList<java.lang.String> orderBy
          How the result of this DMO is ordered?
 StatOperator parentStatOperator
          The statistical operator who instantiates this DMO.
 DataMovementOperator.QuerySet physicalQueryPlan
          Datalog, Conjunctive query or prepared statement acting as the *physical* description of this DMO.
 int predictedBB
          Estimated number of Bound-Bound invocations.
 int PredictedBF
          Estimated number of Bound-Free invocations.
 int PredictedFF
          Estimated number of Free-Free invocations.
 int preFetchFactor
          Parameter for pre-fetching optimization.
 java.util.ArrayList<java.lang.String> selListFromRule
          Part of the schema of the output of this DMO, which is from the conjunctive queries or prepared statement in logicQueryPlan.
 java.util.HashSet<java.lang.String> whichToBound
          Set of variables which will be bounded while evaluating this DMO.
 
Constructor Summary
DataMovementOperator(tuffy.db.RDB _db, StatOperator _parentStatOperator)
          the constructor.
 
Method Summary
 void closePS()
          Cancels rule of this DMO.
 void copyLogicPlanToPhysicalPlanDirectly()
          Copy logic plan to physical plan directly.
 java.sql.PreparedStatement execute(java.lang.String bindingPattern, java.util.ArrayList<java.lang.Integer> bindings)
          Execute this DMO given bindings of variables.
 java.lang.String getAllFreeViewName()
          Gets the view/table name of this DMO in Free-free case.
 java.lang.Integer getNext(int column)
          Get int value in the result of this DMO.
 java.lang.Integer getNext(java.lang.String columnName)
          Get int value in the result of this DMO.
 java.sql.Array getNextArray(int column)
          Get int value in the result of this DMO.
 java.lang.Double getNextDouble(int column)
          Get double value in the result of this DMO.
 java.lang.Double getNextDouble(java.lang.String columnName)
          Get double value in the result of this DMO.
 java.lang.String getNextString(int column)
          Get String value in the result of this DMO.
 java.sql.PreparedStatement getPS(java.lang.String bindingPattern, java.util.ArrayList<java.lang.Integer> bindings)
          Get the prepared statement that will be used to execute this DMO.
 java.lang.Boolean next()
          Whether there are more tuples in the result of this DMO.
 void prepare()
          Methods that prepares for the physical execution of this DMO.
static DataMovementOperator Select(tuffy.db.RDB db, StatOperator _parentStatOperator, DataMovementOperator fromDMO, java.util.ArrayList<java.lang.String> bindings, int... cid)
          Generate a DMO which is a SELECT on the given DMO.
static DataMovementOperator SelectOrderBy(tuffy.db.RDB db, StatOperator _parentStatOperator, DataMovementOperator fromDMO, java.util.ArrayList<java.lang.String> bindings, java.lang.String orderby, int... cid)
          Generate a DMO which is a SELECT ...
static DataMovementOperator UnionAll(tuffy.db.RDB db, StatOperator _parentStatOperator, java.util.List<DataMovementOperator> toBeUnioned, java.lang.String bindingPattern, java.util.ArrayList<java.lang.Integer> bindings, int... cid)
          Get the union of results from a set of DMOs.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db

public tuffy.db.RDB db
RDB object on which this DMO works on.


predictedBB

public int predictedBB
Estimated number of Bound-Bound invocations.


PredictedBF

public int PredictedBF
Estimated number of Bound-Free invocations.


PredictedFF

public int PredictedFF
Estimated number of Free-Free invocations.


isIntermediaDMO

public boolean isIntermediaDMO
Whether this DMO can be used as view/table by other DMOs.


name

public java.lang.String name
Name of table/view generated by this DMO. This name can be used by other DMOs as a view/table directly.


globalID

public static int globalID
Counter for DMO ID.


allowOptimization

public boolean allowOptimization
Whether this DMO allowing optimizations from the optimizer.


hasKnownFetchingOrder

public boolean hasKnownFetchingOrder
Whether this DMO allows pre-fetching.


preFetchFactor

public int preFetchFactor
Parameter for pre-fetching optimization.


parentStatOperator

public StatOperator parentStatOperator
The statistical operator who instantiates this DMO.


logicQueryPlan

public DataMovementOperator.QuerySet logicQueryPlan
Conjunctive query or prepared statement acting as the *logic* description of this DMO. This plan cannot be executed by the executor.


orderBy

public java.util.ArrayList<java.lang.String> orderBy
How the result of this DMO is ordered?


needIndex

public boolean needIndex
Do we need to build index for this DMO's output/intermediate results?


physicalQueryPlan

public DataMovementOperator.QuerySet physicalQueryPlan
Datalog, Conjunctive query or prepared statement acting as the *physical* description of this DMO. When this DMO is executed, it first evaluates all Datalog rules (only evaluate once), and then evaluate the conjunctive query or prepared statement (which may have been optimized). This variable cannot be touched by any ad hoc statistical operator.


finalSelList

public java.util.ArrayList<java.lang.String> finalSelList
The schema for the output of this DMO.


selListFromRule

public java.util.ArrayList<java.lang.String> selListFromRule
Part of the schema of the output of this DMO, which is from the conjunctive queries or prepared statement in logicQueryPlan.


additionalSelList

public java.util.ArrayList<java.lang.String> additionalSelList
Part of the schema of the output of this DMO, which is additionally assigned (i.e., may not be founded in the conjunctive query or prepared statement in logicQueryPlan).


hasPrepared

public boolean hasPrepared
Whether prepare() method has been invoked.


asView

public boolean asView
Whether the output (if any) of this DMO should be regarded as view or materialized table.


whichToBound

public java.util.HashSet<java.lang.String> whichToBound
Set of variables which will be bounded while evaluating this DMO.

Constructor Detail

DataMovementOperator

public DataMovementOperator(tuffy.db.RDB _db,
                            StatOperator _parentStatOperator)
the constructor.

Parameters:
_db -
_parentStatOperator -
Method Detail

UnionAll

public static DataMovementOperator UnionAll(tuffy.db.RDB db,
                                            StatOperator _parentStatOperator,
                                            java.util.List<DataMovementOperator> toBeUnioned,
                                            java.lang.String bindingPattern,
                                            java.util.ArrayList<java.lang.Integer> bindings,
                                            int... cid)
Get the union of results from a set of DMOs. Here each DMO must share exactly the same output schema.

Parameters:
db -
_parentStatOperator -
toBeUnioned - set of DMOs to be unioned.
bindingPattern - bindingPattern of the resulting union. See ConjunctiveQuery.psMap.
bindings -
Returns:

Select

public static DataMovementOperator Select(tuffy.db.RDB db,
                                          StatOperator _parentStatOperator,
                                          DataMovementOperator fromDMO,
                                          java.util.ArrayList<java.lang.String> bindings,
                                          int... cid)
Generate a DMO which is a SELECT on the given DMO.

Parameters:
db -
_parentStatOperator -
fromDMO - the given DMO.
bindings - variables in the WHERE list.
Returns:

SelectOrderBy

public static DataMovementOperator SelectOrderBy(tuffy.db.RDB db,
                                                 StatOperator _parentStatOperator,
                                                 DataMovementOperator fromDMO,
                                                 java.util.ArrayList<java.lang.String> bindings,
                                                 java.lang.String orderby,
                                                 int... cid)
Generate a DMO which is a SELECT ... ORDER BY on the given DMO.

Parameters:
db -
_parentStatOperator -
fromDMO - the given DMO.
bindings - variables in the WHERE list.
orderby -
cid -
Returns:

prepare

public void prepare()
Methods that prepares for the physical execution of this DMO. Invocation of this method will: 1) execute all Datalog rules in the physical plan; 2) build indices for evaluating conjunctive queries; and 3) create view/table for this DMO. This function can be only called once in each Dual decomposition iteration.


execute

public java.sql.PreparedStatement execute(java.lang.String bindingPattern,
                                          java.util.ArrayList<java.lang.Integer> bindings)
Execute this DMO given bindings of variables. This method need to be invoked before next(), getNext(int), getNext(String) etc. can be invoked. This interface is similar to ResultSet in JDBC.

Parameters:
bindingPattern - binding patterns. If this DMO is a conjunctive query (in logic plan), use format as ConjunctiveQuery.psMap (a null value will correspond to all-free case). If this DMO is a prepared statement (in logic plan), this value should be set as null.
bindings - ordered list of constants that will be used to bind variables.
Returns:
PreparedStatement that will be used to execute this DMO.

getPS

public java.sql.PreparedStatement getPS(java.lang.String bindingPattern,
                                        java.util.ArrayList<java.lang.Integer> bindings)
Get the prepared statement that will be used to execute this DMO. See execute(String, ArrayList) (the only difference is this method does not actually execute this DMO).


getAllFreeViewName

public java.lang.String getAllFreeViewName()
Gets the view/table name of this DMO in Free-free case. This name can be referred by other DMO directly w/o aware of the physical plan of this DMO.


next

public java.lang.Boolean next()
Whether there are more tuples in the result of this DMO. See execute(String, ArrayList).

Returns:

getNext

public java.lang.Integer getNext(java.lang.String columnName)
Get int value in the result of this DMO. See execute(String, ArrayList).

Returns:

getNextArray

public java.sql.Array getNextArray(int column)
Get int value in the result of this DMO. See execute(String, ArrayList).

Returns:

getNext

public java.lang.Integer getNext(int column)
Get int value in the result of this DMO. See execute(String, ArrayList).

Returns:

getNextDouble

public java.lang.Double getNextDouble(java.lang.String columnName)
Get double value in the result of this DMO. See execute(String, ArrayList).

Returns:

getNextDouble

public java.lang.Double getNextDouble(int column)
Get double value in the result of this DMO. See execute(String, ArrayList).

Returns:

getNextString

public java.lang.String getNextString(int column)
Get String value in the result of this DMO. See execute(String, ArrayList).

Returns:

closePS

public void closePS()
Cancels rule of this DMO.


copyLogicPlanToPhysicalPlanDirectly

public void copyLogicPlanToPhysicalPlanDirectly()
Copy logic plan to physical plan directly. If a DMO does not allow global optimization, its physical plan will be filled in this fashion. Notes: This function can not be called by ad hoc statistical operator, which should only be aware of the logic plan.