Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -126,6 +126,9 @@ public RexNode makeCast(
// ImmutableList.of(exp, makeZeroLiteral(sourceType)));
}
} else if (OpenSearchTypeFactory.isUserDefinedType(type)) {
if (RexLiteral.isNullLiteral(exp)) {
return super.makeCast(pos, type, exp, matchNullability, safe, format);
}
var udt = ((AbstractExprRelDataType<?>) type).getUdt();
var argExprType = OpenSearchTypeFactory.convertRelDataTypeToExprType(sourceType);
return switch (udt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_ACCOUNT;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BANK;
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_WEBLOGS;
import static org.opensearch.sql.util.MatcherUtils.rows;
import static org.opensearch.sql.util.MatcherUtils.schema;
import static org.opensearch.sql.util.MatcherUtils.verifyDataRows;
Expand All @@ -28,6 +29,7 @@ public void init() throws Exception {
enableCalcite();
loadIndex(Index.ACCOUNT);
loadIndex(Index.BANK);
loadIndex(Index.WEBLOG);
}

@Test
Expand Down Expand Up @@ -236,4 +238,39 @@ public void testAppendWithConflictTypeColumn() throws IOException {
rows(null, null, "NM", 412d),
rows(null, null, "AZ", 414d));
}

@Test
public void testAppendSchemaMergeWithTimestampUDT() throws IOException {
JSONObject actual =
executeQuery(
String.format(
Locale.ROOT,
"source=%s | fields account_number, age | append [ source=%s | fields"
+ " account_number, age, birthdate ] | where isnotnull(birthdate) and"
+ " account_number > 30",
TEST_INDEX_ACCOUNT,
TEST_INDEX_BANK));
verifySchemaInOrder(
actual,
schema("account_number", "bigint"),
schema("age", "bigint"),
schema("age0", "int"),
schema("birthdate", "string"));
verifyDataRows(actual, rows(32, null, 34, "2018-08-11 00:00:00"));
}

@Test
public void testAppendSchemaMergeWithIpUDT() throws IOException {
JSONObject actual =
executeQuery(
String.format(
Locale.ROOT,
"source=%s | fields account_number, age | append [ source=%s | fields host ] |"
+ " where cidrmatch(host, '0.0.0.0/24')",
TEST_INDEX_ACCOUNT,
TEST_INDEX_WEBLOGS));
verifySchemaInOrder(
actual, schema("account_number", "bigint"), schema("age", "bigint"), schema("host", "ip"));
verifyDataRows(actual, rows(null, null, "0.0.0.2"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
setup:
- do:
query.settings:
body:
transient:
plugins.calcite.enabled : true

---
teardown:
- do:
query.settings:
body:
transient:
plugins.calcite.enabled : false

---
"Append UDT fields should merge schema successfully":
- skip:
features:
- headers
- allowed_warnings
- do:
indices.create:
index: log-test1
body:
mappings:
properties:
"timestamp":
type: date
- do:
indices.create:
index: log-test2
body:
mappings:
properties:
"host":
type: ip

- do:
bulk:
index: log-test1
refresh: true
body:
- '{"index": {}}'
- '{ "timestamp" : "2025-09-04T16:15:00.000Z" }'
- do:
bulk:
index: log-test2
refresh: true
body:
- '{"index": {}}'
- '{ "host" : "0.0.0.2" }'

- do:
headers:
Content-Type: 'application/json'
ppl:
body:
query: source=log-test1 | append [ source=log-test2 ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will source=log-test1 | append [ source=log-test2 ] | fields timestamp return - match: { datarows: [["2025-09-04 16:15:00"], [null]] }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synced offline. It will append unique name in case of type conflicts and select fields are also successful


- match: { total: 2 }
- match: { datarows: [["2025-09-04 16:15:00", null], [null, "0.0.0.2"]] }
Loading