/** * Constructor for controls option validator. * * @param name the name of the validator * @param def the default JSON, specified as string * @param ttl the number of queries for which this option should be valid */ public ControlsOptionValidator(final String name, final String def, final int ttl) { super(name, OptionValue.Kind.STRING, OptionValue.createString(OptionType.SYSTEM, name, def)); assert ttl > 0; this.ttl = ttl; }
public StringValidator(String name, String def) { super(name, Kind.STRING, OptionValue.createString(OptionType.SYSTEM, name, def)); } }
protected static OptionValue newStringValue(String value) { return OptionValue.createString(OptionValue.OptionType.SYSTEM, "test-option", value); }
public static OptionValue createOption(Kind kind, OptionType type, String name, String val) { switch (kind) { case BOOLEAN: return createBoolean(type, name, Boolean.valueOf(val)); case LONG: return createLong(type, name, Long.valueOf(val)); case STRING: return createString(type, name, val); case DOUBLE: return createDouble(type, name, Double.valueOf(val)); default: return null; } }
@Override public OptionValue next() { final Entry<String, ConfigValue> e = entries.next(); final ConfigValue cv = e.getValue(); final String name = e.getKey(); OptionValue optionValue = null; switch(cv.valueType()) { case BOOLEAN: optionValue = OptionValue.createBoolean(OptionType.BOOT, name, (Boolean) cv.unwrapped()); break; case LIST: case OBJECT: case STRING: optionValue = OptionValue.createString(OptionType.BOOT, name, cv.render()); break; case NUMBER: optionValue = OptionValue.createLong(OptionType.BOOT, name, ((Number) cv.unwrapped()).longValue()); break; case NULL: throw new IllegalStateException("Config value \"" + name + "\" has NULL type"); } return optionValue; }
@BeforeClass public static void setUpTestNative() { if (System.getProperty("execPreferenceGandivaOnly") != null) { execPreferenceGandivaOnly = System.getProperty("execPreferenceGandivaOnly"); } testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, execPreferenceGandivaOnly)); }
case VARCHAR: case CHAR: return OptionValue.createString(type, name, ((NlsString) object).getValue());
@Override public void close() throws Exception { testContext.getOptions().setOption(OptionValue.createString(OptionType.SYSTEM, validator.getOptionName(), oldValue)); }}; }
@Test public void ok() { OptionValidator validator = newValidator("foo"); // check no fail... validator.validate(OptionValue.createString(OptionValue.OptionType.QUERY, "test-option", "bar")); }
@Test(expected = UserException.class) public void invalidOption() { TypeValidator validator = newValidator("foo"); validator.validate(OptionValue.createString(OptionValue.OptionType.QUERY, "test-option", "bar")); } }
<T extends SingleInputOperator> long runOne(String preference, String expr, TpchTable table, double scale, PhysicalOperator operator, Class<T> clazz) throws Exception { ExecutorService service = Executors.newFixedThreadPool(numThreads); testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, preference)); List<Future<OperatorStats>> futures = new ArrayList<>(); for (int i = 0; i < numThreads; ++i) { Future<OperatorStats> ret = service.submit(new RunWithPreference(table, scale, operator, clazz)); futures.add(ret); } long totalEvalTime = 0; long javaCodegenEvalTime = 0; long gandivaCodegenEvalTime = 0; for (Future<OperatorStats> future : futures) { OperatorStats stats = future.get(); javaCodegenEvalTime += stats.getLongStat(Metric.JAVA_EVALUATE_TIME); gandivaCodegenEvalTime += stats.getLongStat(Metric.GANDIVA_EVALUATE_TIME); } totalEvalTime = javaCodegenEvalTime + gandivaCodegenEvalTime; System.out.println("evaluate time with pref " + preference + " for [" + expr + "] is " + " [" + " eval : " + (javaCodegenEvalTime + gandivaCodegenEvalTime) + "ms " + " javaCodeGen : " + javaCodegenEvalTime + "ms " + " gandivaCodeGen : " + gandivaCodegenEvalTime + "ms " + "]"); return totalEvalTime; }
@Test public void testToDate_Timezone() throws Exception { testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, execPreferenceMixed)); testFunctions(new Object[][]{ {"extractYear(to_date(c0, 'YYYYMMDD HHMISS tzo', 0))","19671211 121212 +08:00", 1967l} }); testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, execPreferenceGandivaOnly)); }
private OptionValue toOptionValue(Setting setting){ if (setting instanceof Setting.BooleanSetting) { return OptionValue.createBoolean(OptionType.SYSTEM, setting.getId(), ((Setting.BooleanSetting)setting).getValue()); } else if(setting instanceof Setting.FloatSetting) { return OptionValue.createDouble(OptionType.SYSTEM, setting.getId(), ((Setting.FloatSetting)setting).getValue()); } else if(setting instanceof Setting.IntegerSetting) { return OptionValue.createLong(OptionType.SYSTEM, setting.getId(), ((Setting.IntegerSetting)setting).getValue()); } else if(setting instanceof Setting.TextSetting) { return OptionValue.createString(OptionType.SYSTEM, setting.getId(), ((Setting.TextSetting)setting).getValue()); } else { throw new IllegalStateException("Unable to handle setting " + setting ); } }
@Test public void testDx14049() throws Exception { try { testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, execPreferenceJava )); testFunctionsCompiledOnly(new Object[][]{ {"months_between(c0, castDATE(c1))",new LocalDate(), new LocalDateTime(), 0.0} }); } finally { testContext.getOptions().setOption(OptionValue.createString( OptionValue.OptionType.SYSTEM, ExecConstants.QUERY_EXEC_OPTION_KEY, execPreferenceGandivaOnly )); } }
public static void setControls(final UserSession session, final String controls) { validateControlsString(controls); final OptionValue opValue = OptionValue.createString(OptionValue.OptionType.SESSION, NODE_CONTROL_INJECTIONS, controls); final OptionManager options = session.getOptions(); try { NODE_CONTROLS_VALIDATOR.validate(opValue); options.setOption(opValue); } catch (final Exception e) { fail("Could not set controls options: " + e.getMessage()); } session.incrementQueryCount(); }
@Test public void testJaninoClassCompiler() throws Exception { logger.debug("Testing JaninoClassCompiler"); sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_OPTION, ClassCompilerSelector.CompilerPolicy.JANINO.name())); ClassCompilerSelector classCompilerSelector = new ClassCompilerSelector(DEFAULT_SABOT_CONFIG, sessionOptions); QueryClassLoader loader = new QueryClassLoader(classCompilerSelector); for (int i = 0; i < ITERATION_COUNT; i++) { compilationInnerClass(loader); } loader.close(); }
public AutoCloseable with(final StringValidator validator, final String value){ final String oldValue = testContext.getOptions().getOption(validator); testContext.getOptions().setOption(OptionValue.createString(OptionType.SYSTEM, validator.getOptionName(), value)); return new AutoCloseable(){ @Override public void close() throws Exception { testContext.getOptions().setOption(OptionValue.createString(OptionType.SYSTEM, validator.getOptionName(), oldValue)); }}; }
@Test public void testJDKClassCompiler() throws Exception { logger.debug("Testing JDKClassCompiler"); sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_OPTION, ClassCompilerSelector.CompilerPolicy.JDK.name())); ClassCompilerSelector classCompilerSelector = new ClassCompilerSelector(DEFAULT_SABOT_CONFIG, sessionOptions); QueryClassLoader loader = new QueryClassLoader(classCompilerSelector); for (int i = 0; i < ITERATION_COUNT; i++) { compilationInnerClass(loader); } loader.close(); }
@Override public void applyOptions(OptionManager manager) { if (enableLeafLimits) { manager.setOption(createBoolean(QUERY, PlannerSettings.ENABLE_LEAF_LIMITS.getOptionName(), true)); manager.setOption(createLong(QUERY, ExecConstants.MAX_WIDTH_GLOBAL_KEY, manager.getOption(PlannerSettings.LEAF_LIMIT_MAX_WIDTH))); manager.setOption(createLong(QUERY, ExecConstants.SLICE_TARGET, 1)); } if (enableOutputLimits) { manager.setOption(createBoolean(QUERY, PlannerSettings.ENABLE_OUTPUT_LIMITS.getOptionName(), true)); } // always store results manager.setOption(createString(QUERY, PlannerSettings.STORE_QUERY_RESULTS.getOptionName(), StoreQueryResultsPolicy.PATH_AND_ATTEMPT_ID.name())); manager.setOption(createString(QUERY, PlannerSettings.QUERY_RESULTS_STORE_TABLE.getOptionName(), queryResultsStorePath)); if (!allowPartitionPruning) { manager.setOption(createBoolean(QUERY, PlannerSettings.ENABLE_PARTITION_PRUNING.getOptionName(), false)); } if (internalSingleThreaded) { manager.setOption(createBoolean(QUERY, ExecConstants.SORT_FILE_BLOCKS.getOptionName(), true)); manager.setOption(createBoolean(QUERY, PlannerSettings.EXCHANGE.getOptionName(), true)); } }
@Test public void testCompilationNoDebug() throws CompileException, ClassNotFoundException, ClassTransformationException, IOException { CodeGenerator<ExampleInner> cg = newCodeGenerator(ExampleInner.class, ExampleTemplateWithInner.class); ClassSet classSet = new ClassSet(null, cg.getDefinition().getTemplateClassName(), cg.getMaterializedClassName()); String sourceCode = cg.generateAndGet(); sessionOptions.setOption(OptionValue.createString(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_OPTION, ClassCompilerSelector.CompilerPolicy.JDK.name())); sessionOptions.setOption(OptionValue.createBoolean(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_DEBUG_OPTION, false)); ClassCompilerSelector classCompilerSelector = new ClassCompilerSelector(DEFAULT_SABOT_CONFIG, sessionOptions); QueryClassLoader loader = new QueryClassLoader(classCompilerSelector); final ClassBytes[] codeWithoutDebug = loader.getClassByteCode(classSet.generated, sourceCode); loader.close(); int sizeWithoutDebug = 0; for (ClassBytes bs : codeWithoutDebug) { sizeWithoutDebug += bs.getBytes().length; } sessionOptions.setOption(OptionValue.createBoolean(OptionType.SESSION, ClassCompilerSelector.JAVA_COMPILER_DEBUG_OPTION, true)); classCompilerSelector = new ClassCompilerSelector(DEFAULT_SABOT_CONFIG, sessionOptions); loader = new QueryClassLoader(classCompilerSelector); final ClassBytes[] codeWithDebug = loader.getClassByteCode(classSet.generated, sourceCode); loader.close(); int sizeWithDebug = 0; for(ClassBytes bs : codeWithDebug) { sizeWithDebug += bs.getBytes().length; } Assert.assertTrue("Debug code is smaller than optimized code!!!", sizeWithDebug > sizeWithoutDebug); logger.debug("Optimized code is {}% smaller than debug code.", (int)((sizeWithDebug - sizeWithoutDebug)/(double)sizeWithDebug*100)); }