@Test public final void testGenerateCuboids() { Column [] columns = new Column[3]; columns[0] = new Column("col1", Type.INT4); columns[1] = new Column("col2", Type.INT8); columns[2] = new Column("col3", Type.FLOAT4); List<Column[]> cube = LogicalPlanner.generateCuboids(columns); assertEquals(((int)Math.pow(2, numCubeColumns)), cube.size()); Set<Set<Column>> cuboids = Sets.newHashSet(); for (Column [] cols : cube) { cuboids.add(Sets.newHashSet(cols)); } for (Set<Column> result : testGenerateCuboidsResult) { assertTrue(cuboids.contains(result)); } }
public static List<Column[]> generateCuboids(Column[] columns) { int numCuboids = (int) Math.pow(2, columns.length); int maxBits = columns.length; List<Column[]> cube = Lists.newArrayList(); List<Column> cuboidCols; cube.add(ALL); for (int cuboidId = 1; cuboidId < numCuboids; cuboidId++) { cuboidCols = Lists.newArrayList(); for (int j = 0; j < maxBits; j++) { int bit = 1 << j; if ((cuboidId & bit) == bit) { cuboidCols.add(columns[j]); } } cube.add(cuboidCols.toArray(new Column[cuboidCols.size()])); } return cube; }
LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContext, LogicalNode> { public static List<Column[]> generateCuboids(Column[] columns) { int numCuboids = (int) Math.pow(2, columns.length); int maxBits = columns.length; List<Column[]> cube = Lists.newArrayList(); List<Column> cuboidCols; cube.add(ALL); for (int cuboidId = 1; cuboidId < numCuboids; cuboidId++) { cuboidCols = Lists.newArrayList(); for (int j = 0; j < maxBits; j++) { int bit = 1 << j; if ((cuboidId & bit) == bit) { cuboidCols.add(columns[j]); } } cube.add(cuboidCols.toArray(new Column[cuboidCols.size()])); } return cube; } }
LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContext, LogicalNode> { public static List<Column[]> generateCuboids(Column[] columns) { int numCuboids = (int) Math.pow(2, columns.length); int maxBits = columns.length; List<Column[]> cube = Lists.newArrayList(); List<Column> cuboidCols; cube.add(ALL); for (int cuboidId = 1; cuboidId < numCuboids; cuboidId++) { cuboidCols = Lists.newArrayList(); for (int j = 0; j < maxBits; j++) { int bit = 1 << j; if ((cuboidId & bit) == bit) { cuboidCols.add(columns[j]); } } cube.add(cuboidCols.toArray(new Column[cuboidCols.size()])); } return cube; } LogicalPlanner(CatalogService catalog); }
LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContext, LogicalNode> { public static List<Column[]> generateCuboids(Column[] columns) { int numCuboids = (int) Math.pow(2, columns.length); int maxBits = columns.length; List<Column[]> cube = Lists.newArrayList(); List<Column> cuboidCols; cube.add(ALL); for (int cuboidId = 1; cuboidId < numCuboids; cuboidId++) { cuboidCols = Lists.newArrayList(); for (int j = 0; j < maxBits; j++) { int bit = 1 << j; if ((cuboidId & bit) == bit) { cuboidCols.add(columns[j]); } } cube.add(cuboidCols.toArray(new Column[cuboidCols.size()])); } return cube; } LogicalPlanner(CatalogService catalog); LogicalPlan createPlan(Expr expr); @VisibleForTesting LogicalPlan createPlan(Expr expr, boolean debug); ExprAnnotator getExprAnnotator(); void preHook(PlanContext context, Stack<Expr> stack, Expr expr); LogicalNode postHook(PlanContext context, Stack<Expr> stack, Expr expr, LogicalNode current); @Override LogicalNode visitProjection(PlanContext context, Stack<Expr> stack, Projection projection); static void verifyProjectedFields(QueryBlock block, Projectable projectable); @Override LimitNode visitLimit(PlanContext context, Stack<Expr> stack, Limit limit); @Override SortNode visitSort(PlanContext context, Stack<Expr> stack, Sort sort); @Override LogicalNode visitHaving(PlanContext context, Stack<Expr> stack, Having expr); @Override LogicalNode visitGroupBy(PlanContext context, Stack<Expr> stack, Aggregation aggregation); static List<Column[]> generateCuboids(Column[] columns); @Override SelectionNode visitFilter(PlanContext context, Stack<Expr> stack, Selection selection); @Override LogicalNode visitJoin(PlanContext context, Stack<Expr> stack, Join join); @Override LogicalNode visitRelationList(PlanContext context, Stack<Expr> stack, RelationList relations); @Override ScanNode visitRelation(PlanContext context, Stack<Expr> stack, Relation expr); TableSubQueryNode visitTableSubQuery(PlanContext context, Stack<Expr> stack, TablePrimarySubQuery expr); @Override LogicalNode visitUnion(PlanContext context, Stack<Expr> stack, SetOperation setOperation); @Override LogicalNode visitExcept(PlanContext context, Stack<Expr> stack, SetOperation setOperation); @Override LogicalNode visitIntersect(PlanContext context, Stack<Expr> stack, SetOperation setOperation); LogicalNode visitInsert(PlanContext context, Stack<Expr> stack, Insert expr); @Override LogicalNode visitCreateTable(PlanContext context, Stack<Expr> stack, CreateTable expr); @Override LogicalNode visitDropTable(PlanContext context, Stack<Expr> stack, DropTable dropTable); static boolean checkIfBeEvaluatedAtGroupBy(EvalNode evalNode, GroupbyNode node); static boolean checkIfBeEvaluatedAtJoin(QueryBlock block, EvalNode evalNode, JoinNode node,
                                                 boolean isTopMostJoin); static boolean checkIfBeEvaluatedAtRelation(QueryBlock block, EvalNode evalNode, RelationNode node); static boolean checkIfBeEvaluatedAtThis(EvalNode evalNode, LogicalNode node); }
LogicalPlanner extends BaseAlgebraVisitor<LogicalPlanner.PlanContext, LogicalNode> { public static List<Column[]> generateCuboids(Column[] columns) { int numCuboids = (int) Math.pow(2, columns.length); int maxBits = columns.length; List<Column[]> cube = Lists.newArrayList(); List<Column> cuboidCols; cube.add(ALL); for (int cuboidId = 1; cuboidId < numCuboids; cuboidId++) { cuboidCols = Lists.newArrayList(); for (int j = 0; j < maxBits; j++) { int bit = 1 << j; if ((cuboidId & bit) == bit) { cuboidCols.add(columns[j]); } } cube.add(cuboidCols.toArray(new Column[cuboidCols.size()])); } return cube; } LogicalPlanner(CatalogService catalog); LogicalPlan createPlan(Expr expr); @VisibleForTesting LogicalPlan createPlan(Expr expr, boolean debug); ExprAnnotator getExprAnnotator(); void preHook(PlanContext context, Stack<Expr> stack, Expr expr); LogicalNode postHook(PlanContext context, Stack<Expr> stack, Expr expr, LogicalNode current); @Override LogicalNode visitProjection(PlanContext context, Stack<Expr> stack, Projection projection); static void verifyProjectedFields(QueryBlock block, Projectable projectable); @Override LimitNode visitLimit(PlanContext context, Stack<Expr> stack, Limit limit); @Override SortNode visitSort(PlanContext context, Stack<Expr> stack, Sort sort); @Override LogicalNode visitHaving(PlanContext context, Stack<Expr> stack, Having expr); @Override LogicalNode visitGroupBy(PlanContext context, Stack<Expr> stack, Aggregation aggregation); static List<Column[]> generateCuboids(Column[] columns); @Override SelectionNode visitFilter(PlanContext context, Stack<Expr> stack, Selection selection); @Override LogicalNode visitJoin(PlanContext context, Stack<Expr> stack, Join join); @Override LogicalNode visitRelationList(PlanContext context, Stack<Expr> stack, RelationList relations); @Override ScanNode visitRelation(PlanContext context, Stack<Expr> stack, Relation expr); TableSubQueryNode visitTableSubQuery(PlanContext context, Stack<Expr> stack, TablePrimarySubQuery expr); @Override LogicalNode visitUnion(PlanContext context, Stack<Expr> stack, SetOperation setOperation); @Override LogicalNode visitExcept(PlanContext context, Stack<Expr> stack, SetOperation setOperation); @Override LogicalNode visitIntersect(PlanContext context, Stack<Expr> stack, SetOperation setOperation); LogicalNode visitInsert(PlanContext context, Stack<Expr> stack, Insert expr); @Override LogicalNode visitCreateTable(PlanContext context, Stack<Expr> stack, CreateTable expr); @Override LogicalNode visitDropTable(PlanContext context, Stack<Expr> stack, DropTable dropTable); static boolean checkIfBeEvaluatedAtGroupBy(EvalNode evalNode, GroupbyNode node); static boolean checkIfBeEvaluatedAtJoin(QueryBlock block, EvalNode evalNode, JoinNode node,
                                                 boolean isTopMostJoin); static boolean checkIfBeEvaluatedAtRelation(QueryBlock block, EvalNode evalNode, RelationNode node); static boolean checkIfBeEvaluatedAtThis(EvalNode evalNode, LogicalNode node); static final Column[] ALL; }