@Test @Ignore("interval") public void checkReadWriteExtended() throws Exception { final String originalFile = "${WORKING_PATH}/src/test/resources/vector/complex/extended.json".replaceAll( Pattern.quote("${WORKING_PATH}"), Matcher.quoteReplacement(TestTools.getWorkingPath())); final String newTable = "TestExtendedTypes/newjson"; try { testNoResult(String.format("ALTER SESSION SET \"%s\" = 'json'", ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName())); testNoResult(String.format("ALTER SESSION SET \"%s\" = true", ExecConstants.JSON_EXTENDED_TYPES.getOptionName())); // create table test("create table dfs_test.tmp.\"%s\" as select * from dfs.\"%s\"", newTable, originalFile); // check query of table. test("select * from dfs_test.tmp.\"%s\"", newTable); // check that original file and new file match. final byte[] originalData = Files.readAllBytes(Paths.get(originalFile)); final byte[] newData = Files.readAllBytes(Paths.get(BaseTestQuery.getDfsTestTmpSchemaLocation() + '/' + newTable + "/0_0_0.json")); assertEquals(new String(originalData), new String(newData)); } finally { testNoResult(String.format("ALTER SESSION SET \"%s\" = '%s'", ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName(), ExecConstants.OUTPUT_FORMAT_VALIDATOR.getDefault().getValue())); testNoResult(String.format("ALTER SESSION SET \"%s\" = %s", ExecConstants.JSON_EXTENDED_TYPES.getOptionName(), ExecConstants.JSON_EXTENDED_TYPES.getDefault().getValue())); } }
@Override public void validate(OptionValue v) { super.validate(v); try { CompilerPolicy.valueOf(v.getStringVal().toUpperCase()); } catch (IllegalArgumentException e) { throw UserException.validationError() .message("Invalid value '%s' specified for option '%s'. Valid values are %s.", v.getStringVal(), getOptionName(), Arrays.toString(CompilerPolicy.values())) .build(logger); } } };
@Test public void testMongoExtendedTypes() throws Exception { final String originalFile = "${WORKING_PATH}/src/test/resources/vector/complex/mongo_extended.json".replaceAll( Pattern.quote("${WORKING_PATH}"), Matcher.quoteReplacement(TestTools.getWorkingPath())); try { testNoResult(String.format("ALTER SESSION SET \"%s\" = 'json'", ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName())); testNoResult(String.format("ALTER SESSION SET \"%s\" = true", ExecConstants.JSON_EXTENDED_TYPES.getOptionName())); int actualRecordCount = testSql(String.format("select * from dfs.\"%s\"", originalFile)); assertEquals( String.format( "Received unexpected number of rows in output: expected=%d, received=%s", 1, actualRecordCount), 1, actualRecordCount); List<QueryDataBatch> resultList = testSqlWithResults(String.format("select * from dfs.\"%s\"", originalFile)); String actual = getResultString(resultList, ","); String expected = "dremio_timestamp_millies,bin,bin1\n2015-07-07T03:59:43.488,dremio,dremio\n"; Assert.assertEquals(expected, actual); } finally { testNoResult(String.format("ALTER SESSION SET \"%s\" = '%s'", ExecConstants.OUTPUT_FORMAT_VALIDATOR.getOptionName(), ExecConstants.OUTPUT_FORMAT_VALIDATOR.getDefault().getValue())); testNoResult(String.format("ALTER SESSION SET \"%s\" = %s", ExecConstants.JSON_EXTENDED_TYPES.getOptionName(), ExecConstants.JSON_EXTENDED_TYPES.getDefault().getValue())); } } }
protected OptionValidator newValidator(String def) { return new TypeValidators.QueryLevelOptionValidation(new TypeValidators.StringValidator("test-option", def)); }
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)); }}; }
@Override public void validate(final OptionValue v) { super.validate(v); if (!isValid(v.getStringVal())) { throw UserException.validationError() .message(String.format("Option %s must be one of: %s.", getOptionName(), valuesSet)) .build(logger); } }
@Override public String getOption(StringValidator validator) { return getOption(validator.getOptionName()).getStringVal(); }
@Override public void close() throws Exception { testContext.getOptions().setOption(OptionValue.createString(OptionType.SYSTEM, validator.getOptionName(), oldValue)); }}; }
private static AutoCloseable withOption(final StringValidator validator, String value) throws Exception{ testNoResult(String.format("ALTER SESSION SET %s%s%s = %s%s%s", SqlUtils.QUOTE, validator.getOptionName(), SqlUtils.QUOTE, SqlUtils.QUOTE, value, SqlUtils.QUOTE)); return new AutoCloseable(){ @Override public void close() throws Exception { testNoResult(String.format("ALTER SESSION RESET %s%s%s", SqlUtils.QUOTE, validator.getOptionName(), SqlUtils.QUOTE)); } }; }
@Override public void validate(OptionValue v) { if (v.getType() != OptionType.SYSTEM) { throw UserException.validationError() .message("Admin related settings can only be set at SYSTEM level scope. Given scope '%s'.", v.getType()) .build(logger); } super.validate(v); } }
@Override public void validate(final OptionValue v) { super.validate(v); if (!isValid(v.getStringVal())) { throw UserException.validationError() .message(String.format("Option %s must be one of: %s.", getOptionName(), valuesSet)) .build(logger); } }
@Override public void close() throws Exception { testNoResult(String.format("ALTER SESSION RESET %s%s%s", SqlUtils.QUOTE, validator.getOptionName(), SqlUtils.QUOTE)); } };