@Test public void tesIsNull() throws Exception { final String query = "select r_name is null as col from cp.\"tpch/region.parquet\" limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.BIT); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@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 testConcatWithMoreThanTwoArgs() throws Exception { final String query = "select concat(r_name, r_name, r_name, 'f') as col \n" + "from cp.\"tpch/region.parquet\" 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) .build() .run(); }
@Test public void testXpath_Double() throws Exception { final String query = "select xpath_double ('<a><b>20</b><c>40</c></a>', 'a/b * a/c') as col \n" + "from hive.kv \n" + "limit 0"; final MajorType majorType = Types.optional(MinorType.FLOAT8); final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testDate_Part() throws Exception { final String query = "select date_part('year', date '2008-2-23') as col \n" + "from cp.\"tpch/region.parquet\" \n" + "limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.BIGINT); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testTimestampDiff() throws Exception { final String query = "select timestampdiff(SECOND, to_timestamp('2014-02-13 00:30:30','YYYY-MM-DD HH24:MI:SS'), to_timestamp('2014-02-13 00:30:30','YYYY-MM-DD HH24:MI:SS')) as col \n" + "from cp.\"tpch/region.parquet\" \n" + "limit 0"; final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); final MajorType majorType = Types.required(MinorType.INT); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testSQRTDecimalLiteral() throws Exception { final String query = "SELECT sqrt(5.1) as col \n" + "from cp.\"tpch/nation.parquet\" \n" + "limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.FLOAT8); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testWindowNTILE() throws Exception { final String query = "select ntile(1) over(order by position_id) as col \n" + "from cp.\"employee.json\" \n" + "limit 0"; final MajorType majorType = Types.required(MinorType.BIGINT); final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testSQRTIntegerLiteral() throws Exception { final String query = "SELECT sqrt(4) as col \n" + "from cp.\"tpch/nation.parquet\" \n" + "limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.FLOAT8); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@Test public void testEqualBetweenIntervalAndTimestampDiff() throws Exception { final String query = "select to_timestamp('2016-11-02 10:00:00','YYYY-MM-DD HH:MI:SS') + interval '10-11' year to month as col \n" + "from cp.\"tpch/region.parquet\" \n" + "where (to_timestamp('2016-11-02 10:00:00','YYYY-MM-DD HH:MI:SS') - to_timestamp('2016-01-01 10:00:00','YYYY-MM-DD HH:MI:SS') < interval '5 10:00:00' day to second) \n" + "limit 0"; final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); final MajorType majorType = Types.required(MinorType.TIMESTAMP); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
@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(); }
@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 testSumRequiredType() throws Exception { final String query = "SELECT \n" + "SUM(CASE WHEN (CAST(n_regionkey AS INT) = 1) THEN 1 ELSE 0 END) AS col \n" + "FROM cp.\"tpch/nation.parquet\" \n" + "GROUP BY CAST(n_regionkey AS INT) \n" + "limit 0"; List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList(); MajorType majorType = Types.required(MinorType.BIGINT); expectedSchema.add(Pair.of(SchemaPath.getSimplePath("col"), majorType)); testBuilder() .sqlQuery(query) .schemaBaseLine(expectedSchema) .build() .run(); }
public void substringTest(final String query) throws Exception { @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("s"), Types.optional(MinorType.VARCHAR))); testBuilder() .sqlQuery(query) .baselineColumns("s") .ordered() .baselineValues("Sheri") .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
public void concatTest(final String query) throws Exception { @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("c"), Types.optional(MinorType.VARCHAR))); testBuilder() .sqlQuery(query) .baselineColumns("c") .ordered() .baselineValues("Sheri NowmerGraduate Degree") .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
@Test public void position() throws Exception { final String query = "select position('i' in full_name) from " + viewName+ " where full_name like '%i%'"; @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("EXPR$0"), Types.optional(MinorType.INT))); testBuilder() .sqlQuery(query) .ordered() .baselineColumns("EXPR$0") .baselineValues(5) .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
@Test public void castSum() throws Exception { final String query = "SELECT CAST(SUM(position_id) AS INT) AS s FROM cp.\"employee.json\""; @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("s"), Types.optional(MinorType.INT))); testBuilder() .sqlQuery(query) .ordered() .baselineColumns("s") .baselineValues(18422) .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
@Test public void charlength() throws Exception { final String query = "select char_length(full_name) from " + viewName+ " where full_name like '%i%'"; @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("EXPR$0"), Types.optional(MinorType.INT))); testBuilder() .sqlQuery(query) .ordered() .baselineColumns("EXPR$0") .baselineValues(12) .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
@Test public void rank() throws Exception { final String query = "SELECT RANK() OVER(PARTITION BY employee_id ORDER BY employee_id) AS r FROM " + viewName; @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("r"), Types.required(MinorType.BIGINT))); testBuilder() .sqlQuery(query) .ordered() .baselineColumns("r") .baselineValues(1L) .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }
@Test public void extract() throws Exception { final String query = "SELECT EXTRACT(YEAR FROM hire_date) AS e FROM " + viewName; @SuppressWarnings("unchecked") final List<Pair<SchemaPath, MajorType>> expectedSchema = Lists.newArrayList( Pair.of(SchemaPath.getSimplePath("e"), Types.optional(MinorType.BIGINT))); testBuilder() .sqlQuery(query) .baselineColumns("e") .ordered() .baselineValues(1994L) .go(); testBuilder() .sqlQuery(wrapLimit0(query)) .schemaBaseLine(expectedSchema) .go(); checkThatQueryPlanIsOptimized(query); }