@Override public void close() throws Exception { testNoResult(String.format("ALTER SESSION RESET %s%s%s", SqlUtils.QUOTE, validator.getOptionName(), SqlUtils.QUOTE)); } };
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)); } }; }
@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())); } }
@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())); } } }
@Override public void close() throws Exception { testContext.getOptions().setOption(OptionValue.createString(OptionType.SYSTEM, validator.getOptionName(), oldValue)); }}; }
@Override public String getOption(StringValidator validator) { return getOption(validator.getOptionName()).getStringVal(); }
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)); }}; }