use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class AbstractParsedStmt method producesOneRowOutput.
// Function evaluates whether the statement results in at most
// one output row. This is implemented for single table by checking
// value equivalence of predicates in where clause and checking
// if all defined unique indexes are in value equivalence set.
// Returns true if the statement results is at most one output
// row else false
protected boolean producesOneRowOutput() {
if (m_tableAliasMap.size() != 1) {
return false;
}
// Get the table. There's only one.
StmtTableScan scan = m_tableAliasMap.values().iterator().next();
Table table = getTableFromDB(scan.getTableName());
// May be sub-query? If can't find the table there's no use to continue.
if (table == null) {
return false;
}
// Get all the indexes defined on the table
CatalogMap<Index> indexes = table.getIndexes();
if (indexes == null || indexes.size() == 0) {
// no indexes defined on the table
return false;
}
// Collect value equivalence expression for the SQL statement
HashMap<AbstractExpression, Set<AbstractExpression>> valueEquivalence = analyzeValueEquivalence();
// If no value equivalence filter defined in SQL statement, there's no use to continue
if (valueEquivalence.isEmpty()) {
return false;
}
// Collect all tve expressions from value equivalence set which have equivalence
// defined to parameterized or constant value expression.
// Eg: T.A = ? or T.A = 1
Set<AbstractExpression> parameterizedConstantKeys = new HashSet<>();
// get all the keys
Set<AbstractExpression> valueEquivalenceKeys = valueEquivalence.keySet();
for (AbstractExpression key : valueEquivalenceKeys) {
if (key instanceof TupleValueExpression) {
Set<AbstractExpression> values = valueEquivalence.get(key);
for (AbstractExpression value : values) {
if ((value instanceof ParameterValueExpression) || (value instanceof ConstantValueExpression)) {
TupleValueExpression tve = (TupleValueExpression) key;
parameterizedConstantKeys.add(tve);
}
}
}
}
// index defined on table appears in tve equivalence expression gathered above.
for (Index index : indexes) {
// Perform lookup only on pure column indices which are unique
if (!index.getUnique() || !index.getExpressionsjson().isEmpty()) {
continue;
}
Set<AbstractExpression> indexExpressions = new HashSet<>();
CatalogMap<ColumnRef> indexColRefs = index.getColumns();
for (ColumnRef indexColRef : indexColRefs) {
Column col = indexColRef.getColumn();
TupleValueExpression tve = new TupleValueExpression(scan.getTableName(), scan.getTableAlias(), col.getName(), col.getName(), col.getIndex());
indexExpressions.add(tve);
}
if (parameterizedConstantKeys.containsAll(indexExpressions)) {
return true;
}
}
return false;
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class CompiledPlan method setParamIndexes.
// A reusable step extracted from boundParamIndexes so it can be applied to two different
// sources of bindings, IndexScans and IndexCounts.
private static void setParamIndexes(BitSet ints, List<AbstractExpression> params) {
for (AbstractExpression ae : params) {
assert (ae instanceof ParameterValueExpression);
ParameterValueExpression pve = (ParameterValueExpression) ae;
int param = pve.getParameterIndex();
ints.set(param);
}
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class CompiledPlan method parameterTypes.
// This is assumed to be called only after parameters has been fully initialized.
public VoltType[] parameterTypes() {
if (m_parameterTypes == null) {
m_parameterTypes = new VoltType[parameters.length];
int ii = 0;
for (ParameterValueExpression param : parameters) {
m_parameterTypes[ii++] = param.getValueType();
}
}
return m_parameterTypes;
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class TestScanPlanNode method testOutputSchemaOverriddenProjection.
// test that if someone provides their own inline projection
// that the output schema of the scan node consists of the output
// schema of the projection. Updates will do this so that the
// inlined projection fills the values of the output tuples correctly
// before it attempts to update them
public void testOutputSchemaOverriddenProjection() {
AbstractScanPlanNode dut = new SeqScanPlanNode(TABLE1, TABLE1);
// Create an output schema like we might see for an inlined projection
// generated for update. We'll have 4 output columns, the first will
// be the tuple address, the second one a parameter expression, next
// will be a constant, and the other will be a more complex expression
// that uses some TVEs.
NodeSchema proj_schema = new NodeSchema();
String[] cols = new String[4];
TupleAddressExpression col1_exp = new TupleAddressExpression();
proj_schema.addColumn("", "", "tuple_address", "tuple_address", col1_exp);
cols[0] = "tuple_address";
// update column 1 with a parameter value
ParameterValueExpression col2_exp = new ParameterValueExpression();
col2_exp.setParameterIndex(0);
col2_exp.setValueType(COLTYPES[1]);
col2_exp.setValueSize(COLTYPES[1].getLengthInBytesForFixedTypes());
// XXX I'm not sure what to do with the name for the updated column yet.
// I think it should be an alias and not the original table name/col name
proj_schema.addColumn(TABLE1, TABLE1, COLS[1], COLS[1], col2_exp);
cols[1] = COLS[1];
// Update column 3 with a constant value
ConstantValueExpression col3_exp = new ConstantValueExpression();
col3_exp.setValueType(COLTYPES[3]);
col3_exp.setValueSize(COLTYPES[3].getLengthInBytesForFixedTypes());
col3_exp.setValue("3.14159");
proj_schema.addColumn(TABLE1, TABLE1, COLS[3], COLS[3], col3_exp);
cols[2] = COLS[3];
// update column 4 with a sum of columns 0 and 2
OperatorExpression col4_exp = new OperatorExpression();
col4_exp.setValueType(COLTYPES[4]);
col4_exp.setValueSize(COLTYPES[4].getLengthInBytesForFixedTypes());
col4_exp.setExpressionType(ExpressionType.OPERATOR_PLUS);
TupleValueExpression left = new TupleValueExpression(TABLE1, TABLE1, COLS[0], COLS[0], 0);
left.setValueType(COLTYPES[0]);
left.setValueSize(COLTYPES[0].getLengthInBytesForFixedTypes());
TupleValueExpression right = new TupleValueExpression(TABLE1, TABLE1, COLS[2], COLS[2], 0);
right.setValueType(COLTYPES[2]);
right.setValueSize(COLTYPES[2].getLengthInBytesForFixedTypes());
col4_exp.setLeft(left);
col4_exp.setRight(right);
proj_schema.addColumn(TABLE1, TABLE1, COLS[4], "C1", col4_exp);
cols[3] = COLS[4];
ProjectionPlanNode proj_node = new ProjectionPlanNode(proj_schema);
dut.addInlinePlanNode(proj_node);
System.out.println("ProjSchema: " + proj_schema.toString());
dut.generateOutputSchema(m_voltdb.getDatabase());
NodeSchema dut_schema = dut.getOutputSchema();
System.out.println(dut_schema.toString());
for (int i = 0; i < cols.length; i++) {
SchemaColumn col = null;
if (i == 0) {
col = dut_schema.find("", "", cols[i], cols[i]);
} else {
col = dut_schema.find(TABLE1, TABLE1, cols[i], cols[i]);
}
assertNotNull(col);
assertEquals(col.getExpression().getExpressionType(), ExpressionType.VALUE_TUPLE);
}
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class AbstractParsedStmt method toString.
@Override
public String toString() {
String retval = "SQL:\n\t" + m_sql + "\n";
retval += "PARAMETERS:\n\t";
for (Map.Entry<Integer, ParameterValueExpression> paramEntry : m_paramsByIndex.entrySet()) {
retval += paramEntry.getValue().toString() + " ";
}
retval += "\nTABLE SOURCES:\n\t";
for (Table table : m_tableList) {
retval += table.getTypeName() + " ";
}
retval += "\nSCAN COLUMNS:\n";
boolean hasAll = true;
for (StmtTableScan tableScan : m_tableAliasMap.values()) {
List<SchemaColumn> scanColumns = tableScan.getScanColumns();
if (scanColumns.isEmpty()) {
continue;
}
hasAll = false;
retval += "\tTable Alias: " + tableScan.getTableAlias() + ":\n";
for (SchemaColumn col : scanColumns) {
retval += "\t\tColumn: " + col.getColumnName() + ": ";
retval += col.getExpression().toString() + "\n";
}
}
if (hasAll) {
retval += "\tALL\n";
}
retval += "\nJOIN TREE :\n";
if (m_joinTree != null) {
retval += m_joinTree.toString();
}
retval += "NO TABLE SELECTION LIST:\n";
int i = 0;
for (AbstractExpression expr : m_noTableSelectionList) {
retval += "\t(" + String.valueOf(i++) + ") " + expr.toString() + "\n";
}
return retval;
}
Aggregations