use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestPlansScalarSubQueries method testSelectParameterScalar.
public void testSelectParameterScalar() {
AbstractPlanNode pn = compile("select r2.c, (select d from r1 where r1.c = ? ) scalar from r2");
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
AbstractPlanNode proj = pn.getInlinePlanNode(PlanNodeType.PROJECTION);
NodeSchema schema = proj.getOutputSchema();
assertEquals(2, schema.size());
SchemaColumn col = schema.getColumns().get(1);
assertTrue(col != null);
assertEquals("SCALAR", col.getColumnName());
AbstractExpression colExpr = col.getExpression();
assertEquals(ExpressionType.VALUE_SCALAR, colExpr.getExpressionType());
assertTrue(colExpr.getLeft() instanceof AbstractSubqueryExpression);
AbstractSubqueryExpression subqueryExpr = (AbstractSubqueryExpression) colExpr.getLeft();
AbstractPlanNode subquery = subqueryExpr.getSubqueryNode();
assertEquals(PlanNodeType.SEQSCAN, subquery.getPlanNodeType());
AbstractExpression pred = ((SeqScanPlanNode) subquery).getPredicate();
assertEquals(ExpressionType.VALUE_PARAMETER, pred.getRight().getExpressionType());
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestPlansScalarSubQueries method testSelectCorrelatedScalarWithGroupby.
public void testSelectCorrelatedScalarWithGroupby() {
String sql = "select franchise_id, count(*) as stores_in_category_AdHoc, " + " (select category from store_types where type_id = stores.type_id) as store_category " + "from stores group by franchise_id, type_id;";
AbstractPlanNode pn = compile(sql);
pn = pn.getChild(0);
assertTrue(pn instanceof ProjectionPlanNode);
NodeSchema schema = pn.getOutputSchema();
assertEquals(3, schema.size());
SchemaColumn col = schema.getColumns().get(2);
assertTrue(col != null);
assertEquals("STORE_CATEGORY", col.getColumnName());
assertTrue(col.getExpression() instanceof ScalarValueExpression);
pn = pn.getChild(0);
assertTrue(pn instanceof AbstractScanPlanNode);
assertNotNull(pn.getInlinePlanNode(PlanNodeType.HASHAGGREGATE));
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class TestPlansJoin method perJoinOpTestBasicInnerJoin.
private void perJoinOpTestBasicInnerJoin(JoinOp joinOp) {
String query;
String pattern;
AbstractPlanNode pn;
List<SchemaColumn> selectColumns;
// SELECT * with ON clause should return all columns from all tables
query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
pn = compileToTopDownTree(query, 5, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
query = "SELECT R1.A, R1.C, D FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
query = "SELECT R1.A, C, R1.D FROM R1 JOIN R2 USING(C)";
pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
query = "SELECT R1.A, R2.C, R1.D FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C";
pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
assertEquals("R1", selectColumns.get(0).getTableName());
assertEquals("R2", selectColumns.get(1).getTableName());
// The output table for C can be either R1 or R2 because it's an INNER join
query = "SELECT R1.A, C, R1.D FROM R1 JOIN R2 USING(C)";
pn = compileToTopDownTree(query, 3, PlanNodeType.SEND, PlanNodeType.PROJECTION, PlanNodeType.NESTLOOP, PlanNodeType.SEQSCAN, PlanNodeType.SEQSCAN);
selectColumns = pn.getOutputSchema().getColumns();
assertEquals("R1", selectColumns.get(0).getTableName());
String table = selectColumns.get(1).getTableName();
assertTrue("R2".equals(table) || "R1".equals(table));
table = selectColumns.get(2).getTableName();
assertEquals("R1", table);
query = "SELECT R2.C FROM R1 JOIN R2 ON R1.X" + joinOp + "R2.X";
pattern = "user lacks privilege or object not found: R1.X";
failToCompile(query, pattern);
query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C AND 1";
pattern = "data type of expression is not boolean";
failToCompile(query, pattern);
query = "SELECT * FROM R1 JOIN R2 ON R1.C" + joinOp + "R2.C AND MOD(3,1)=1";
pattern = "Join with filters that do not depend on joined tables is not supported in VoltDB";
failToCompile(query, pattern);
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class StmtSubqueryScan method promoteSinglePartitionInfo.
/**
* upgrade single partitioning expression to parent level
* add the info to equality sets and input value equivalence
* @param valueEquivalence
* @param eqSets
*/
public void promoteSinglePartitionInfo(HashMap<AbstractExpression, Set<AbstractExpression>> valueEquivalence, Set<Set<AbstractExpression>> eqSets) {
assert (m_subqueriesPartitioning != null);
if (m_subqueriesPartitioning.getCountOfPartitionedTables() == 0 || m_subqueriesPartitioning.requiresTwoFragments()) {
return;
}
// This subquery is a single partitioned query on partitioned tables
// promoting the single partition expression up to its parent level.
AbstractExpression spExpr = m_subqueriesPartitioning.singlePartitioningExpression();
for (SchemaColumn col : m_partitioningColumns) {
AbstractExpression tveKey = col.getExpression();
assert (tveKey instanceof TupleValueExpression);
Set<AbstractExpression> values = null;
if (valueEquivalence.containsKey(tveKey)) {
values = valueEquivalence.get(tveKey);
} else if (valueEquivalence.containsKey(spExpr)) {
values = valueEquivalence.get(spExpr);
} else {
for (SchemaColumn otherCol : m_partitioningColumns) {
if (col != otherCol && valueEquivalence.containsKey(otherCol.getExpression())) {
values = valueEquivalence.get(otherCol.getExpression());
break;
}
}
if (values == null) {
values = new HashSet<>();
}
}
updateEqualSets(values, valueEquivalence, eqSets, tveKey, spExpr);
}
}
use of org.voltdb.plannodes.SchemaColumn in project voltdb by VoltDB.
the class StmtSubqueryScan method processTVE.
@Override
public AbstractExpression processTVE(TupleValueExpression expr, String columnName) {
Integer idx = m_outputColumnIndexMap.get(Pair.of(columnName, expr.getDifferentiator()));
if (idx == null) {
throw new PlanningErrorException("Mismatched columns " + columnName + " in subquery");
}
SchemaColumn schemaCol = m_outputColumnList.get(idx.intValue());
expr.setColumnIndex(idx.intValue());
expr.setTypeSizeAndInBytes(schemaCol);
return expr;
}
Aggregations