Skip to content

Commit

Permalink
there
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Jan 14, 2025
1 parent c09ecfe commit bf001d1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ private Set<String> getPhysicalColumns(CursorBuildSpec spec)
Set<String> physicalColumns = spec.getPhysicalColumns();
if (physicalColumns != null) {
physicalColumns = new HashSet<>(physicalColumns);
for (VirtualColumn vc : virtualColumns.getVirtualColumns()) {
physicalColumns.addAll(vc.requiredColumns());
}
if (filter != null) {
for (String column : filter.getRequiredColumns()) {
if (!spec.getVirtualColumns().exists(column)) {
if (!spec.getVirtualColumns().exists(column) && !virtualColumns.exists(column)) {
physicalColumns.add(column);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ boolean forceSubQuery(SourceDesc sourceDesc)

boolean filteredDatasourceAllowed()
{
// return joinType == JoinPosition.NONE;
return joinType != JoinPosition.RIGHT;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,8 @@ public void testInnerJoinTwoLookupsToTableUsingNumericColumn(Map<String, Object>
);
}

@DecoupledTestConfig(quidemReason = QuidemTestCaseReason.EQUIV_PLAN_CAST_MATERIALIZED_EARLIER)
@DecoupledTestConfig(ignoreExpectedQueriesReason = IgnoreQueriesReason.XL)
// @DecoupledTestConfig(quidemReason = QuidemTestCaseReason.EQUIV_PLAN_CAST_MATERIALIZED_EARLIER)
@MethodSource("provideQueryContexts")
@ParameterizedTest(name = "{0}")
public void testInnerJoinTwoLookupsToTableUsingNumericColumnInReverse(Map<String, Object> queryContext)
Expand All @@ -1683,7 +1684,8 @@ public void testInnerJoinTwoLookupsToTableUsingNumericColumnInReverse(Map<String
cannotVectorize();

testQuery(
"SELECT COUNT(*)\n"
// "SELECT l1.k,l2.k,foo.m1\n"
"SELECT l1.v\n"
+ "FROM lookup.lookyloo l1\n"
+ "INNER JOIN lookup.lookyloo l2 ON l1.k = l2.k\n"
+ "INNER JOIN foo on l2.k = foo.m1",
Expand Down Expand Up @@ -1731,6 +1733,63 @@ public void testInnerJoinTwoLookupsToTableUsingNumericColumnInReverse(Map<String
);
}


@DecoupledTestConfig(ignoreExpectedQueriesReason = IgnoreQueriesReason.XL)
@Test
@MethodSource("provideQueryContexts")
@ParameterizedTest(name = "{0}")
public void testCNO(Map<String, Object> queryContext)

{

testQuery(
// "SELECT l1.k,l2.k,foo.m1\n"
"SELECT f1 from numfoo where f1 = dim6"
,
queryContext,
ImmutableList.of(
Druids.newTimeseriesQueryBuilder()
.dataSource(
join(
join(
new LookupDataSource("lookyloo"),
new LookupDataSource("lookyloo"),
"j0.",
equalsCondition(
makeColumnExpression("k"),
makeColumnExpression("j0.k")
),
JoinType.INNER
),
new QueryDataSource(
newScanQueryBuilder()
.dataSource(CalciteTests.DATASOURCE1)
.intervals(querySegmentSpec(Filtration.eternity()))
.columns("m1")
.columnTypes(ColumnType.FLOAT)
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
"_j0.",
equalsCondition(
makeExpression(ColumnType.DOUBLE, "CAST(\"j0.k\", 'DOUBLE')"),
DruidExpression.ofColumn(ColumnType.FLOAT, "_j0.m1")
),
JoinType.INNER
)
)
.intervals(querySegmentSpec(Filtration.eternity()))
.granularity(Granularities.ALL)
.aggregators(new CountAggregatorFactory("a0"))
.context(QUERY_CONTEXT_DEFAULT)
.build()
),
ImmutableList.of(
new Object[]{1F}
)
);
}

@MethodSource("provideQueryContexts")
@ParameterizedTest(name = "{0}")
public void testInnerJoinLookupTableTable(Map<String, Object> queryContext)
Expand Down
42 changes: 22 additions & 20 deletions sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,27 +442,29 @@ private void verifyQuery(QueryResults queryResults)
expectedQueries.size(),
recordedQueries.size()
);
for (int i = 0; i < expectedQueries.size(); i++) {
Query<?> expectedQuery = expectedQueries.get(i);
Query<?> actualQuery = recordedQueries.get(i);
Assert.assertEquals(
StringUtils.format("query #%d: %s", i + 1, builder.sql),
expectedQuery,
actualQuery
);
if(true) {
for (int i = 0; i < expectedQueries.size(); i++) {
Query<?> expectedQuery = expectedQueries.get(i);
Query<?> actualQuery = recordedQueries.get(i);
Assert.assertEquals(
StringUtils.format("query #%d: %s", i + 1, builder.sql),
expectedQuery,
actualQuery
);

try {
// go through some JSON serde and back, round tripping both queries and comparing them to each other, because
// Assert.assertEquals(recordedQueries.get(i), stringAndBack) is a failure due to a sorted map being present
// in the recorded queries, but it is a regular map after deserialization
final String recordedString = queryJsonMapper.writeValueAsString(actualQuery);
final Query<?> stringAndBack = queryJsonMapper.readValue(recordedString, Query.class);
final String expectedString = queryJsonMapper.writeValueAsString(expectedQuery);
final Query<?> expectedStringAndBack = queryJsonMapper.readValue(expectedString, Query.class);
Assert.assertEquals(expectedStringAndBack, stringAndBack);
}
catch (JsonProcessingException e) {
Assert.fail(e.getMessage());
try {
// go through some JSON serde and back, round tripping both queries and comparing them to each other, because
// Assert.assertEquals(recordedQueries.get(i), stringAndBack) is a failure due to a sorted map being present
// in the recorded queries, but it is a regular map after deserialization
final String recordedString = queryJsonMapper.writeValueAsString(actualQuery);
final Query<?> stringAndBack = queryJsonMapper.readValue(recordedString, Query.class);
final String expectedString = queryJsonMapper.writeValueAsString(expectedQuery);
final Query<?> expectedStringAndBack = queryJsonMapper.readValue(expectedString, Query.class);
Assert.assertEquals(expectedStringAndBack, stringAndBack);
}
catch (JsonProcessingException e) {
Assert.fail(e.getMessage());
}
}
}
}
Expand Down

0 comments on commit bf001d1

Please sign in to comment.