use of org.apache.calcite.plan.hep.HepProgramBuilder in project hive by apache.
the class TestHiveReduceExpressionsWithStatsRule method before.
@Before
public void before() {
HepProgramBuilder programBuilder = new HepProgramBuilder();
programBuilder.addRuleInstance(HiveReduceExpressionsWithStatsRule.INSTANCE);
planner = new HepPlanner(programBuilder.build());
JavaTypeFactoryImpl typeFactory = new JavaTypeFactoryImpl();
RexBuilder rexBuilder = new RexBuilder(typeFactory);
final RelOptCluster optCluster = RelOptCluster.create(planner, rexBuilder);
RelDataType rowTypeMock = typeFactory.createStructType(MyRecord.class);
Mockito.doReturn(rowTypeMock).when(tableMock).getRowType();
LogicalTableScan tableScan = LogicalTableScan.create(optCluster, tableMock, Collections.emptyList());
doReturn(tableScan).when(tableMock).toRel(ArgumentMatchers.any());
Mockito.doReturn(tableMock).when(schemaMock).getTableForMember(Matchers.any());
statObj = new ColStatistics("_int", "int");
Mockito.doReturn(Lists.newArrayList(statObj)).when(tableMock).getColStat(Matchers.anyListOf(Integer.class), Matchers.eq(false));
Mockito.doReturn(hiveTableMDMock).when(tableMock).getHiveTableMD();
Mockito.doReturn(tableParams).when(hiveTableMDMock).getParameters();
builder = HiveRelFactories.HIVE_BUILDER.create(optCluster, schemaMock);
StatsSetupConst.setStatsStateForCreateTable(tableParams, Lists.newArrayList("_int"), StatsSetupConst.TRUE);
tableParams.put(StatsSetupConst.ROW_COUNT, "3");
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project hive by apache.
the class TestRelSignature method before.
@Before
public void before() {
HepProgramBuilder programBuilder = new HepProgramBuilder();
programBuilder.addRuleInstance(new HivePointLookupOptimizerRule.FilterCondition(2));
planner = new HepPlanner(programBuilder.build());
JavaTypeFactoryImpl typeFactory = new JavaTypeFactoryImpl();
RexBuilder rexBuilder = new RexBuilder(typeFactory);
final RelOptCluster optCluster = RelOptCluster.create(planner, rexBuilder);
RelDataType rowTypeMock = typeFactory.createStructType(MyRecord.class);
LogicalTableScan tableScan = LogicalTableScan.create(optCluster, tableMock, Collections.emptyList());
doReturn(tableScan).when(tableMock).toRel(ArgumentMatchers.any());
doReturn(rowTypeMock).when(tableMock).getRowType();
doReturn(tableMock).when(schemaMock).getTableForMember(Matchers.any());
lenient().doReturn(hiveTableMDMock).when(tableMock).getHiveTableMD();
builder = HiveRelFactories.HIVE_BUILDER.create(optCluster, schemaMock);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project hazelcast by hazelcast.
the class QueryConverter method rewriteSubqueries.
/**
* Special substep of an initial query conversion which eliminates correlated subqueries, converting them to various forms
* of joins. It is used instead of "expand" flag due to bugs in Calcite (see {@link #EXPAND}).
*
* @param rel Initial relation.
* @return Resulting relation.
*/
private static RelNode rewriteSubqueries(RelNode rel) {
HepProgramBuilder hepProgramBuilder = new HepProgramBuilder();
hepProgramBuilder.addRuleInstance(CoreRules.FILTER_SUB_QUERY_TO_CORRELATE);
hepProgramBuilder.addRuleInstance(CoreRules.PROJECT_SUB_QUERY_TO_CORRELATE);
hepProgramBuilder.addRuleInstance(CoreRules.JOIN_SUB_QUERY_TO_CORRELATE);
// TODO: [sasha] Move more rules to unconditionally rewrite rel tree.
hepProgramBuilder.addRuleInstance(CoreRules.UNION_MERGE);
hepProgramBuilder.addRuleInstance(CoreRules.UNION_TO_DISTINCT);
HepPlanner planner = new HepPlanner(hepProgramBuilder.build(), Contexts.empty(), true, null, RelOptCostImpl.FACTORY);
planner.setRoot(rel);
return planner.findBestExp();
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class CalcitePrepareImpl method convert_.
private ParseResult convert_(Context context, String sql, boolean analyze, boolean fail, CalciteCatalogReader catalogReader, SqlValidator validator, SqlNode sqlNode1) {
final JavaTypeFactory typeFactory = context.getTypeFactory();
final Convention resultConvention = enableBindable ? BindableConvention.INSTANCE : EnumerableConvention.INSTANCE;
final HepPlanner planner = new HepPlanner(new HepProgramBuilder().build());
planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
final SqlToRelConverter.ConfigBuilder configBuilder = SqlToRelConverter.configBuilder().withTrimUnusedFields(true);
if (analyze) {
configBuilder.withConvertTableAccess(false);
}
final CalcitePreparingStmt preparingStmt = new CalcitePreparingStmt(this, context, catalogReader, typeFactory, context.getRootSchema(), null, planner, resultConvention, createConvertletTable());
final SqlToRelConverter converter = preparingStmt.getSqlToRelConverter(validator, catalogReader, configBuilder.build());
final RelRoot root = converter.convertQuery(sqlNode1, false, true);
if (analyze) {
return analyze_(validator, sql, sqlNode1, root, fail);
}
return new ConvertResult(this, validator, sql, sqlNode1, validator.getValidatedNodeType(sqlNode1), root);
}
use of org.apache.calcite.plan.hep.HepProgramBuilder in project calcite by apache.
the class RelOptRulesTest method testReduceConstantsCalc.
@Test
public void testReduceConstantsCalc() throws Exception {
// This reduction does not work using
// ReduceExpressionsRule.PROJECT_INSTANCE or FILTER_INSTANCE,
// only CALC_INSTANCE, because we need to pull the project expression
// upper('table')
// into the condition
// upper('table') = 'TABLE'
// and reduce it to TRUE. Only in the Calc are projects and conditions
// combined.
HepProgram program = new HepProgramBuilder().addRuleInstance(FilterProjectTransposeRule.INSTANCE).addRuleInstance(FilterSetOpTransposeRule.INSTANCE).addRuleInstance(FilterToCalcRule.INSTANCE).addRuleInstance(ProjectToCalcRule.INSTANCE).addRuleInstance(CalcMergeRule.INSTANCE).addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE).addRuleInstance(PruneEmptyRules.UNION_INSTANCE).addRuleInstance(ProjectToCalcRule.INSTANCE).addRuleInstance(CalcMergeRule.INSTANCE).addRuleInstance(ReduceExpressionsRule.CALC_INSTANCE).build();
// Result should be same as typing
// SELECT * FROM (VALUES ('TABLE ', 'T')) AS T(U, S)
checkPlanning(program, "select * from (\n" + " select upper(substring(x FROM 1 FOR 2) || substring(x FROM 3)) as u,\n" + " substring(x FROM 1 FOR 1) as s\n" + " from (\n" + " select 'table' as x from (values (true))\n" + " union\n" + " select 'view' from (values (true))\n" + " union\n" + " select 'foreign table' from (values (true))\n" + " )\n" + ") where u = 'TABLE'");
}
Aggregations