Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@Getter
@EqualsAndHashCode(callSuper = false)
public class QualifiedName extends UnresolvedExpression {
public static final String DELIMITER = ".";
private final List<String> parts;

public QualifiedName(String name) {
Expand Down Expand Up @@ -94,7 +95,7 @@ public QualifiedName rest() {
}

public String toString() {
return String.join(".", this.parts);
return String.join(DELIMITER, this.parts);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ private static RexNode resolveFieldAccess(
if (length == parts.size() - start) {
return field;
} else {
String itemName = joinParts(parts, length + start, parts.size() - 1 - length);
return createItemAccess(field, itemName, context);
String itemName = joinParts(parts, length + start, parts.size() - length);
return context.relBuilder.alias(
createItemAccess(field, itemName, context),
String.join(QualifiedName.DELIMITER, parts.subList(start, parts.size())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void init() throws Exception {
loadIndex(Index.LOGS);
loadIndex(Index.WORKER);
loadIndex(Index.WORK_INFORMATION);
loadIndex(Index.WEBLOG);
}

@Override
Expand Down Expand Up @@ -1416,4 +1417,16 @@ public void testTopKThenSortExplain() throws IOException {
+ "| sort age "
+ "| fields age"));
}

@Test
public void testInternalItemAccessOnStructs() throws IOException {
String expected = loadExpectedPlan("access_struct_subfield_with_item.yaml");
assertYamlEqualsIgnoreId(
expected,
explainQueryYaml(
String.format(
"source=%s | eval info = geoip('dummy-datasource', host) | fields host, info,"
+ " info.dummy_sub_field",
TEST_INDEX_WEBLOGS)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,23 @@ public void testGeoIpEnrichmentWithIpFieldAsInput() throws IOException {
rows("10.0.0.1", Map.of("country", "USA")),
rows("fd12:2345:6789:1:a1b2:c3d4:e5f6:789a", Map.of("country", "India")));
}

@Test
public void testGeoIpEnrichmentAccessingSubField() throws IOException {
JSONObject result =
executeQuery(
String.format(
"source=%s | where method='POST' | eval info = geoip('%s', host) | fields host,"
+ " info, info.country",
TEST_INDEX_WEBLOGS, DATASOURCE_NAME));
verifySchema(
result, schema("host", "ip"), schema("info", "struct"), schema("info.country", "string"));
verifyDataRows(
result,
rows("10.0.0.1", Map.of("country", "USA", "city", "Seattle"), "USA"),
rows(
"fd12:2345:6789:1:a1b2:c3d4:e5f6:789a",
Map.of("country", "India", "city", "Bengaluru"),
"India"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(host=[$0], info=[GEOIP('dummy-datasource':VARCHAR, $0)], info.dummy_sub_field=[ITEM(GEOIP('dummy-datasource':VARCHAR, $0), 'dummy_sub_field')])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_weblogs]])
physical: |
EnumerableCalc(expr#0=[{inputs}], expr#1=['dummy-datasource':VARCHAR], expr#2=[GEOIP($t1, $t0)], expr#3=['dummy_sub_field'], expr#4=[ITEM($t2, $t3)], host=[$t0], $f1=[$t2], $f2=[$t4])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_weblogs]], PushDownContext=[[PROJECT->[host], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","_source":{"includes":["host"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)])
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(host=[$0], info=[GEOIP('dummy-datasource':VARCHAR, $0)], info.dummy_sub_field=[ITEM(GEOIP('dummy-datasource':VARCHAR, $0), 'dummy_sub_field')])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_weblogs]])
physical: |
EnumerableLimit(fetch=[10000])
EnumerableCalc(expr#0..11=[{inputs}], expr#12=['dummy-datasource':VARCHAR], expr#13=[GEOIP($t12, $t0)], expr#14=['dummy_sub_field'], expr#15=[ITEM($t13, $t14)], host=[$t0], info=[$t13], info.dummy_sub_field=[$t15])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_weblogs]])
Loading