@Override public void evaluate() throws Throwable { clearRecordedQueries(); final Consumer<Object> function = query -> { try { recordedQueries.add((Query) query); log.info( "Issued query: %s", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(query) ); } catch (Exception e) { log.warn(e, "Failed to serialize query: %s", query); } }; try (final Hook.Closeable unhook = Hook.QUERY_PLAN.add(function)) { base.evaluate(); } } };
/** @deprecated Use {@link #add(Consumer)}. */ @SuppressWarnings("Guava") @Deprecated // to be removed in 2.0 public <T, R> Closeable add(final Function<T, R> handler) { return add((Consumer<T>) handler::apply); }
/** @deprecated Use {@link #add(Consumer)}. */ @SuppressWarnings("Guava") @Deprecated // to be removed in 2.0 public <T, R> Closeable add(final Function<T, R> handler) { return add((Consumer<T>) handler::apply); }
public static synchronized void addHook() { if (globalProgramClosable == null) { globalProgramClosable = Hook.PROGRAM.add(program()); } }
@Test public <T> void testReduceCaseNullabilityChange() throws Exception { HepProgram program = new HepProgramBuilder() .addRuleInstance(ReduceExpressionsRule.FILTER_INSTANCE) .addRuleInstance(ReduceExpressionsRule.PROJECT_INSTANCE) .build(); try (Hook.Closeable a = Hook.REL_BUILDER_SIMPLIFY.add(Hook.propertyJ(false))) { checkPlanning(program, "select case when empno = 1 then 1 when 1 IS NOT NULL then 2 else null end as qx " + "from emp"); } }
public RelRoot toRel(final SqlNode validatedNode) { if (planner == null) { planner = new VolcanoPlanner(costFactory, settings); planner.setExecutor(new DrillConstExecutor(functions, util, settings)); planner.clearRelTraitDefs(); planner.addRelTraitDef(ConventionTraitDef.INSTANCE); planner.addRelTraitDef(DrillDistributionTraitDef.INSTANCE); planner.addRelTraitDef(RelCollationTraitDef.INSTANCE); } if (cluster == null) { initCluster(); } final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(new Expander(), validator, catalog, cluster, DrillConvertletTable.INSTANCE, sqlToRelConverterConfig); /* * Sets value to false to avoid simplifying project expressions * during creating new projects since it may cause changing data mode * which causes to assertion errors during type validation */ Hook.REL_BUILDER_SIMPLIFY.add(Hook.propertyJ(false)); //To avoid unexpected column errors set a value of top to false final RelRoot rel = sqlToRelConverter.convertQuery(validatedNode, false, false); return rel.withRel(sqlToRelConverter.flattenTypes(rel.rel, true)); }