use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class TupleScanPlanNode method loadFromJSONObject.
@Override
public void loadFromJSONObject(JSONObject jobj, Database db) throws JSONException {
super.loadFromJSONObject(jobj, db);
if (jobj.has(Members.PARAM_IDX.name())) {
JSONArray paramIdxArray = jobj.getJSONArray(Members.PARAM_IDX.name());
int paramSize = paramIdxArray.length();
assert (m_outputSchema != null && paramSize == m_outputSchema.size());
for (int i = 0; i < paramSize; ++i) {
int paramIdx = paramIdxArray.getInt(i);
ParameterValueExpression pve = new ParameterValueExpression();
pve.setParameterIndex(paramIdx);
AbstractExpression expr = m_outputSchema.getColumns().get(i).getExpression();
pve.setValueSize(expr.getValueSize());
pve.setValueType(expr.getValueType());
m_columnList.add(pve);
}
}
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class TupleScanPlanNode method generateOutputSchema.
@Override
public void generateOutputSchema(Database db) {
if (m_tableSchema == null) {
m_tableSchema = new NodeSchema();
int columnIdx = 1;
for (AbstractExpression colExpr : m_columnList) {
assert (colExpr instanceof ParameterValueExpression);
ParameterValueExpression pve = (ParameterValueExpression) colExpr;
// must produce a tuple value expression for this column.
String columnName = "C" + Integer.toString(columnIdx);
TupleValueExpression tve = new TupleValueExpression(m_targetTableName, m_targetTableAlias, columnName, columnName, pve, columnIdx);
m_tableSchema.addColumn(m_targetTableName, m_targetTableAlias, columnName, columnName, tve);
++columnIdx;
}
m_outputSchema = m_tableSchema;
m_hasSignificantOutputSchema = true;
}
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class TestPlansSubQueries method testParameters.
public void testParameters() {
AbstractPlanNode pn = compile("select A1 FROM (SELECT A A1 FROM R1 WHERE A > ? LIMIT 10) TEMP WHERE A1 < ?");
pn = pn.getChild(0);
assertTrue(pn instanceof SeqScanPlanNode);
AbstractExpression p = ((SeqScanPlanNode) pn).getPredicate();
assertTrue(p != null);
assertTrue(p instanceof ComparisonExpression);
AbstractExpression cp = p.getLeft();
assertTrue(cp instanceof TupleValueExpression);
cp = p.getRight();
assertTrue(cp instanceof ParameterValueExpression);
assertEquals(1, ((ParameterValueExpression) cp).getParameterIndex().intValue());
assertTrue(pn.getChildCount() == 1);
assertTrue(pn.getChild(0) instanceof SeqScanPlanNode);
SeqScanPlanNode sc = (SeqScanPlanNode) pn.getChild(0);
assertTrue(sc.getPredicate() != null);
p = sc.getPredicate();
assertTrue(p instanceof ComparisonExpression);
cp = p.getRight();
assertTrue(cp instanceof ParameterValueExpression);
assertEquals(0, ((ParameterValueExpression) cp).getParameterIndex().intValue());
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class ParsedUnionStmt method parseOrderColumn.
/**
* This is a stripped down version of the ParsedSelectStmt.parseOrderColumn. Since the SET ops
* are not allowed to have aggregate expressions (HAVING, GROUP BY) (except the individual SELECTS)
* all the logic handling the aggregates is omitted here
* @param orderByNode
* @param leftmostSelectChild
*/
private void parseOrderColumn(VoltXMLElement orderByNode, ParsedSelectStmt leftmostSelectChild) {
ParsedColInfo.ExpressionAdjuster adjuster = new ParsedColInfo.ExpressionAdjuster() {
@Override
public AbstractExpression adjust(AbstractExpression expr) {
// Union itself can't have aggregate expression
return expr;
}
};
// Get the display columns from the first child
List<ParsedColInfo> displayColumns = leftmostSelectChild.orderByColumns();
ParsedColInfo order_col = ParsedColInfo.fromOrderByXml(leftmostSelectChild, orderByNode, adjuster);
AbstractExpression order_exp = order_col.expression;
assert (order_exp != null);
// helps later when trying to determine ORDER BY coverage (for determinism).
for (ParsedColInfo col : displayColumns) {
if (col.alias.equals(order_col.alias) || col.expression.equals(order_exp)) {
col.orderBy = true;
col.ascending = order_col.ascending;
order_col.alias = col.alias;
order_col.columnName = col.columnName;
order_col.tableName = col.tableName;
break;
}
}
assert (!(order_exp instanceof ConstantValueExpression));
assert (!(order_exp instanceof ParameterValueExpression));
m_orderColumns.add(order_col);
}
use of org.voltdb.expressions.ParameterValueExpression in project voltdb by VoltDB.
the class AbstractParsedStmt method addHonoraryOrderByExpressions.
/**
* Given a set of order-by expressions and a select list, which is a list of
* columns, each with an expression and an alias, expand the order-by list
* with new expressions which could be on the order-by list without changing
* the sort order and which are otherwise helpful.
*/
protected void addHonoraryOrderByExpressions(HashSet<AbstractExpression> orderByExprs, List<ParsedColInfo> candidateColumns) {
// of joins is the content of ticket ENG-8677.
if (m_tableAliasMap.size() != 1) {
return;
}
HashMap<AbstractExpression, Set<AbstractExpression>> valueEquivalence = analyzeValueEquivalence();
for (ParsedColInfo colInfo : candidateColumns) {
AbstractExpression colExpr = colInfo.expression;
if (colExpr instanceof TupleValueExpression) {
Set<AbstractExpression> tveEquivs = valueEquivalence.get(colExpr);
if (tveEquivs != null) {
for (AbstractExpression expr : tveEquivs) {
if (expr instanceof ParameterValueExpression || expr instanceof ConstantValueExpression) {
orderByExprs.add(colExpr);
}
}
}
}
}
// We know there's exactly one.
StmtTableScan scan = m_tableAliasMap.values().iterator().next();
// Get the table. There's only one.
Table table = getTableFromDB(scan.getTableName());
// there's no use to continue.
if (table == null) {
return;
}
// Now, look to see if there is a constraint which can help us.
// If there is a unique constraint on a set of columns, and all
// the constrained columns are in the order by list, then all
// the columns in the table can be added to the order by list.
//
// The indices we care about have columns, but the order by list has expressions.
// Extract the columns from the order by list.
Set<Column> orderByColumns = new HashSet<>();
for (AbstractExpression expr : orderByExprs) {
if (expr instanceof TupleValueExpression) {
TupleValueExpression tve = (TupleValueExpression) expr;
Column col = table.getColumns().get(tve.getColumnName());
orderByColumns.add(col);
}
}
CatalogMap<Constraint> constraints = table.getConstraints();
// If we have no constraints, there's nothing more to do here.
if (constraints == null) {
return;
}
Set<Index> indices = new HashSet<>();
for (Constraint constraint : constraints) {
Index index = constraint.getIndex();
// Only use column indices for now.
if (index != null && index.getUnique() && index.getExpressionsjson().isEmpty()) {
indices.add(index);
}
}
for (ParsedColInfo colInfo : candidateColumns) {
AbstractExpression expr = colInfo.expression;
if (expr instanceof TupleValueExpression) {
TupleValueExpression tve = (TupleValueExpression) expr;
// So, we remember this and early-out.
for (Index index : indices) {
CatalogMap<ColumnRef> columns = index.getColumns();
// If all the columns in this index are in the current
// honorary order by list, then we can add all the
// columns in this table to the honorary order by list.
boolean addAllColumns = true;
for (ColumnRef cr : columns) {
Column col = cr.getColumn();
if (orderByColumns.contains(col) == false) {
addAllColumns = false;
break;
}
}
if (addAllColumns) {
for (Column addCol : table.getColumns()) {
// We have to convert this to a TVE to add
// it to the orderByExprs. We will use -1
// for the column index. We don't have a column
// alias.
TupleValueExpression ntve = new TupleValueExpression(tve.getTableName(), tve.getTableAlias(), addCol.getName(), null, -1);
orderByExprs.add(ntve);
}
// Don't forget to remember to forget the other indices. (E. Presley, 1955)
break;
}
}
}
}
}
Aggregations