use of org.apache.druid.segment.virtual.ExpressionVirtualColumn in project druid by druid-io.
the class LookupSerdeModuleTest method testExpressionVirtualColumnSerde.
@Test
public void testExpressionVirtualColumnSerde() throws Exception {
final ExpressionVirtualColumn virtualColumn = new ExpressionVirtualColumn("v", "lookup(xxx, 'beep')", ColumnType.STRING, injector.getInstance(ExprMacroTable.class));
Assert.assertEquals(virtualColumn, objectMapper.readValue(objectMapper.writeValueAsBytes(virtualColumn), VirtualColumn.class));
}
use of org.apache.druid.segment.virtual.ExpressionVirtualColumn in project druid by druid-io.
the class ExpressionsTest method testRegexpLikeAsFilter.
@Test
public void testRegexpLikeAsFilter() {
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("f.")), Collections.emptyList(), new RegexDimFilter("s", "f.", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("o")), Collections.emptyList(), // Column "s" contains an 'o', but not at the beginning, so we don't match
new RegexDimFilter("s", "o", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("x.")), Collections.emptyList(), new RegexDimFilter("s", "x.", null), false);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("s"), testHelper.makeLiteral("")), Collections.emptyList(), new RegexDimFilter("s", "", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("newliney"), testHelper.makeLiteral("^beep$")), Collections.emptyList(), new RegexDimFilter("newliney", "^beep$", null), false);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("newliney"), testHelper.makeLiteral("^beep\\nboop$")), Collections.emptyList(), new RegexDimFilter("newliney", "^beep\\nboop$", null), true);
testHelper.testFilter(new RegexpLikeOperatorConversion().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("Z"), testHelper.makeInputRef("s")), testHelper.makeLiteral("x(.)")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('Z',\"s\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new RegexDimFilter("v0", "x(.)", null), false);
}
use of org.apache.druid.segment.virtual.ExpressionVirtualColumn in project druid by druid-io.
the class ExpressionsTest method testContainsAsFilter.
@Test
public void testContainsAsFilter() {
testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("there")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("there", true), null), true);
testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("There")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("There", true), null), false);
testHelper.testFilter(ContainsOperatorConversion.caseInsensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("There")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("There", false), null), true);
testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("what")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("what", true), null), true);
testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("there")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("there", true), null), true);
testHelper.testFilter(ContainsOperatorConversion.caseInsensitive().calciteOperator(), ImmutableList.of(testHelper.makeCall(SqlStdOperatorTable.CONCAT, testHelper.makeLiteral("what is"), testHelper.makeInputRef("spacey")), testHelper.makeLiteral("What")), ImmutableList.of(new ExpressionVirtualColumn("v0", "concat('what is',\"spacey\")", ColumnType.STRING, TestExprMacroTable.INSTANCE)), new SearchQueryDimFilter("v0", new ContainsSearchQuerySpec("What", false), null), true);
testHelper.testFilter(ContainsOperatorConversion.caseSensitive().calciteOperator(), ImmutableList.of(testHelper.makeInputRef("spacey"), testHelper.makeLiteral("")), Collections.emptyList(), new SearchQueryDimFilter("spacey", new ContainsSearchQuerySpec("", true), null), true);
}
use of org.apache.druid.segment.virtual.ExpressionVirtualColumn in project druid by druid-io.
the class CalciteCorrelatedQueryTest method testCorrelatedSubqueryWithLeftFilter_leftDirectAccessDisabled.
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testCorrelatedSubqueryWithLeftFilter_leftDirectAccessDisabled(Map<String, Object> queryContext) throws Exception {
cannotVectorize();
testQuery("select country, ANY_VALUE(\n" + " select max(\"users\") from (\n" + " select floor(__time to day), count(*) \"users\" from visits f where f.country = visits.country group by 1\n" + " )\n" + " ) as \"dailyVisits\"\n" + "from visits \n" + " where city = 'B' and __time between '2021-01-01 01:00:00' AND '2021-01-02 23:59:59'" + " group by 1", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new QueryDataSource(newScanQueryBuilder().dataSource(CalciteTests.USERVISITDATASOURCE).intervals(querySegmentSpec(Intervals.of("2021-01-01T01:00:00.000Z/2021-01-02T23:59:59.001Z"))).filters(selector("city", "B", null)).columns("__time", "city", "country").build()), new QueryDataSource(GroupByQuery.builder().setDataSource(GroupByQuery.builder().setDataSource(CalciteTests.USERVISITDATASOURCE).setQuerySegmentSpec(querySegmentSpec(Intervals.ETERNITY)).setVirtualColumns(new ExpressionVirtualColumn("v0", "timestamp_floor(\"__time\",'P1D',null,'UTC')", ColumnType.LONG, TestExprMacroTable.INSTANCE)).setDimFilter(not(selector("country", null, null))).setDimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG), new DefaultDimensionSpec("country", "d1")).setAggregatorSpecs(new CountAggregatorFactory("a0")).setContext(withTimestampResultContext(queryContext, "d0", Granularities.DAY)).setGranularity(new AllGranularity()).build()).setQuerySegmentSpec(querySegmentSpec(Intervals.ETERNITY)).setDimensions(new DefaultDimensionSpec("d1", "_d0")).setAggregatorSpecs(new LongMaxAggregatorFactory("_a0", "a0")).setGranularity(new AllGranularity()).setContext(queryContext).build()), "j0.", equalsCondition(makeColumnExpression("country"), makeColumnExpression("j0._d0")), JoinType.LEFT)).setQuerySegmentSpec(querySegmentSpec(Intervals.ETERNITY)).setDimensions(new DefaultDimensionSpec("country", "d0")).setAggregatorSpecs(new LongAnyAggregatorFactory("a0", "j0._a0")).setGranularity(new AllGranularity()).setContext(queryContext).build()), ImmutableList.of(new Object[] { "canada", 4L }));
}
use of org.apache.druid.segment.virtual.ExpressionVirtualColumn in project druid by druid-io.
the class CalciteCorrelatedQueryTest method testCorrelatedSubqueryWithLeftFilter.
@Test
@Parameters(source = QueryContextForJoinProvider.class)
public void testCorrelatedSubqueryWithLeftFilter(Map<String, Object> queryContext) throws Exception {
cannotVectorize();
queryContext = withLeftDirectAccessEnabled(queryContext);
testQuery("select country, ANY_VALUE(\n" + " select max(\"users\") from (\n" + " select floor(__time to day), count(*) \"users\" from visits f where f.country = visits.country group by 1\n" + " )\n" + " ) as \"dailyVisits\"\n" + "from visits \n" + " where city = 'B' and __time between '2021-01-01 01:00:00' AND '2021-01-02 23:59:59'" + " group by 1", queryContext, ImmutableList.of(GroupByQuery.builder().setDataSource(join(new TableDataSource(CalciteTests.USERVISITDATASOURCE), new QueryDataSource(GroupByQuery.builder().setDataSource(GroupByQuery.builder().setDataSource(CalciteTests.USERVISITDATASOURCE).setQuerySegmentSpec(querySegmentSpec(Intervals.ETERNITY)).setVirtualColumns(new ExpressionVirtualColumn("v0", "timestamp_floor(\"__time\",'P1D',null,'UTC')", ColumnType.LONG, TestExprMacroTable.INSTANCE)).setDimFilter(not(selector("country", null, null))).setDimensions(new DefaultDimensionSpec("v0", "d0", ColumnType.LONG), new DefaultDimensionSpec("country", "d1")).setAggregatorSpecs(new CountAggregatorFactory("a0")).setContext(withTimestampResultContext(queryContext, "d0", Granularities.DAY)).setGranularity(new AllGranularity()).build()).setQuerySegmentSpec(querySegmentSpec(Intervals.ETERNITY)).setDimensions(new DefaultDimensionSpec("d1", "_d0")).setAggregatorSpecs(new LongMaxAggregatorFactory("_a0", "a0")).setGranularity(new AllGranularity()).setContext(queryContext).build()), "j0.", equalsCondition(makeColumnExpression("country"), makeColumnExpression("j0._d0")), JoinType.LEFT, selector("city", "B", null))).setQuerySegmentSpec(querySegmentSpec(Intervals.of("2021-01-01T01:00:00.000Z/2021-01-02T23:59:59.001Z"))).setDimensions(new DefaultDimensionSpec("country", "d0")).setAggregatorSpecs(new LongAnyAggregatorFactory("a0", "j0._a0")).setGranularity(new AllGranularity()).setContext(queryContext).build()), ImmutableList.of(new Object[] { "canada", 4L }));
}
Aggregations