@Test public void testRepeatedColumnMatching() throws Exception { try { testBuilder() .sqlQuery("select * from cp.\"store/json/schema_change_int_to_string.json\"") .optionSettingQueriesForTestQuery("alter system set \"store.json.all_text_mode\" = true") .ordered() .jsonBaselineFile("testframework/schema_change_int_to_string_non-matching.json") .optionSettingQueriesForBaseline("alter system set \"store.json.all_text_mode\" = true") .build().run(); } catch (Exception ex) { assertThat(ex.getMessage(), CoreMatchers.containsString("at position 1 column '`field_1`' mismatched values,")); assertThat(ex.getMessage(), CoreMatchers.containsString("expected (JsonStringArrayList):")); assertThat(ex.getMessage(), CoreMatchers.containsString("[\"5\",\"2\",\"3\",\"4\",\"1\",\"2\"]")); assertThat(ex.getMessage(), CoreMatchers.containsString("but received (JsonStringArrayList):")); assertThat(ex.getMessage(), CoreMatchers.containsString("[\"5\"]")); // this indicates successful completion of the test test("alter system set \"store.json.all_text_mode\" = false"); return; } throw new Exception("Test framework verification failed, expected failure on order check."); }
@Test(expected = AssertionError.class) public void testSchemaTestBuilderSetInvalidBaselineRecords() throws Exception { final String query = "SELECT ltrim('dremio') as col FROM (VALUES(1)) limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.VARCHAR); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .baselineRecords(Collections.<Map<String, Object>>emptyList()) .build() .run(); }
@Test public void testCSVVerification_missing_records_fails() throws Exception { try { testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\"") .ordered() .csvBaselineFile("testframework/small_test_data_extra.tsv") .baselineTypes(MinorType.BIGINT, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name") .build().run(); } catch (AssertionError ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Incorrect number of rows returned by query.")); assertTrue(ex.getMessage(), ex.getMessage().contains("expected:<7> but was:<5>")); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on missing records."); }
@Test public void testCSVVerificationOfOrder_checkFailure() throws Throwable { try { testBuilder() .sqlQuery("select columns[0] as employee_id, columns[1] as first_name, columns[2] as last_name from cp.\"testframework/small_test_data_reordered.tsv\"") .ordered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineColumns("employee_id", "first_name", "last_name") .build().run(); } catch (Exception ex) { assertThat(ex.getMessage(), CoreMatchers.containsString("at position 0 column '`employee_id`' mismatched values,")); assertThat(ex.getMessage(), CoreMatchers.containsString("expected (String):")); assertThat(ex.getMessage(), CoreMatchers.containsString("but received (String):")); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on order check."); }
@Test public void testComplexJSON_all_text() throws Exception { testBuilder() .sqlQuery("select * from cp.\"store/json/schema_change_int_to_string.json\"") .optionSettingQueriesForTestQuery("alter system set \"store.json.all_text_mode\" = true") .ordered() .jsonBaselineFile("store/json/schema_change_int_to_string.json") .optionSettingQueriesForBaseline("alter system set \"store.json.all_text_mode\" = true") .build().run(); testBuilder() .sqlQuery("select * from cp.\"store/json/schema_change_int_to_string.json\"") .optionSettingQueriesForTestQuery("alter system set \"store.json.all_text_mode\" = true") .unOrdered() // Check other verification method with same files .jsonBaselineFile("store/json/schema_change_int_to_string.json") .optionSettingQueriesForBaseline("alter system set \"store.json.all_text_mode\" = true") .build().run(); test("alter system set \"store.json.all_text_mode\" = false"); }
@Test(expected = AssertionError.class) public void testSchemaTestBuilderSetInvalidBaselineValues() throws Exception { final String query = "SELECT ltrim('dremio') as col FROM (VALUES(1)) limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.VARCHAR); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .baselineValues(new Object[0]) .build() .run(); }
public void testDecimalBaseline() throws Exception { try { test(String.format("alter session set \"%s\" = true", PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY)); testBuilder() .sqlQuery("select cast(dec_col as decimal(38,2)) dec_col from cp.\"testframework/decimal_test.json\"") .unOrdered() test(String.format("alter session set \"%s\" = false", PlannerSettings.ENABLE_DECIMAL_DATA_TYPE_KEY));
@Test(expected = AssertionError.class) public void testSchemaTestBuilderSetInvalidBaselineColumns() throws Exception { final String query = "SELECT ltrim('dremio') as col FROM (VALUES(1)) limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.VARCHAR); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .baselineColumns("col") .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testEmptyResultSet() throws Exception { testBuilder() .sqlQuery("select * from cp.\"store/json/json_simple_with_null.json\" where 1=0") .expectsEmptyResultSet() .build().run(); try { testBuilder() .sqlQuery("select * from cp.\"store/json/json_simple_with_null.json\"") .expectsEmptyResultSet() .build().run(); } catch (AssertionError ex) { assertTrue(ex.getMessage().contains("Different number of records returned - expected:<0> but was:<4>")); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on unexpected records."); }
@Test public void testCSVVerificationOfTypes() throws Throwable { try { testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\"") .ordered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineTypes(MinorType.INT, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name") .build().run(); } catch (Exception ex) { assertThat(ex.getMessage(), CoreMatchers.containsString("at position 0 column '`employee_id`' mismatched values,")); assertThat(ex.getMessage(), CoreMatchers.containsString("expected (Integer)")); assertThat(ex.getMessage(), CoreMatchers.containsString("but received (Long):")); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on type check."); }
@Test public void testCSVVerification_missing_column_fails() throws Exception { try { testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\"") .ordered() .csvBaselineFile("testframework/small_test_data_extra_col.tsv") .baselineTypes(MinorType.BIGINT, MinorType.VARCHAR, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name", "address") .build().run(); } catch (Exception ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Expected column(s) `address`, not found in result set")); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on missing column."); }
@Test public void testCSVVerification_extra_records_fails() throws Exception { try { testBuilder() .sqlQuery("select " + CSV_COLS + " from cp.\"testframework/small_test_data_extra.tsv\"") .ordered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineTypes(MinorType.BIGINT, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name") .build().run(); } catch (AssertionError ex) { assertTrue(ex.getMessage(), ex.getMessage().startsWith("Incorrect number of rows returned by query.")); assertTrue(ex.getMessage(), ex.getMessage().contains("expected:<5> but was:<7>")); // this indicates successful completion of the test return; } fail("Test framework verification failed, expected failure for extra records."); }
@Test public void testMapOrdering() throws Exception { testBuilder() .sqlQuery("select * from cp.\"/testframework/map_reordering.json\"") .unOrdered() .jsonBaselineFile("testframework/map_reordering2.json") .build().run(); }
@Test public void testBasicJSON() throws Exception { testBuilder() .sqlQuery("select * from cp.\"scan_json_test_3.json\"") .ordered() .jsonBaselineFile("/scan_json_test_3.json") .build().run(); testBuilder() .sqlQuery("select * from cp.\"scan_json_test_3.json\"") .unOrdered() // Check other verification method with same files .jsonBaselineFile("/scan_json_test_3.json") .build().run(); }
@Test public void testCSVVerification_extra_column_fails() throws Exception { try { testBuilder() .sqlQuery("select " + CSV_COLS + ", columns[3] as address from cp.\"testframework/small_test_data_extra_col.tsv\"") .ordered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineTypes(MinorType.BIGINT, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name") .build().run(); } catch (AssertionError ex) { assertEquals("Unexpected extra column `address` returned by query.", ex.getMessage()); // this indicates successful completion of the test return; } throw new Exception("Test framework verification failed, expected failure on extra column."); }
@Test public void testCSVVerificationOfUnorderedComparison() throws Throwable { testBuilder() .sqlQuery("select columns[0] as employee_id, columns[1] as first_name, columns[2] as last_name from cp.\"testframework/small_test_data_reordered.tsv\"") .unOrdered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineColumns("employee_id", "first_name", "last_name") .build().run(); }
@Test public void testBaselineValsVerification() throws Exception { testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\" limit 1") .ordered() .baselineColumns("employee_id", "first_name", "last_name") .baselineValues(12l, "Jewel", "Creek") .build().run(); testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\" limit 1") .unOrdered() .baselineColumns("employee_id", "first_name", "last_name") .baselineValues(12l, "Jewel", "Creek") .build().run(); }
typeMap.put(TestBuilder.parsePath("employee_id"), Types.optional(MinorType.INT)); typeMap.put(TestBuilder.parsePath("last_name"), Types.optional(MinorType.VARCHAR)); testBuilder() .sqlQuery("select cast(columns[0] as int) employee_id, columns[1] as first_name, columns[2] as last_name from cp.\"testframework/small_test_data_reordered.tsv\"") .unOrdered() testBuilder() .sqlQuery("select cast(columns[0] as int) employee_id, columns[1] as first_name, columns[2] as last_name from cp.\"testframework/small_test_data_reordered.tsv\"") .unOrdered()
@Test public void testCSVVerification() throws Exception { testBuilder() .sqlQuery("select employee_id, first_name, last_name from cp.\"testframework/small_test_data.json\"") .ordered() .csvBaselineFile("testframework/small_test_data.tsv") .baselineTypes(MinorType.BIGINT, MinorType.VARCHAR, MinorType.VARCHAR) .baselineColumns("employee_id", "first_name", "last_name") .build().run(); }
@Test public void testBaselineValsVerificationWithNulls() throws Exception { testBuilder() .sqlQuery("select * from cp.\"store/json/json_simple_with_null.json\"") .ordered() .baselineColumns("a", "b") .baselineValues(5l, 10l) .baselineValues(7l, null) .baselineValues(null, null) .baselineValues(9l, 11l) .build().run(); testBuilder() .sqlQuery("select * from cp.\"store/json/json_simple_with_null.json\"") .unOrdered() .baselineColumns("a", "b") .baselineValues(5l, 10l) .baselineValues(9l, 11l) .baselineValues(7l, null) .baselineValues(null, null) .build().run(); }