Skip to content

Commit 0ff7d97

Browse files
committed
update validation logic
Signed-off-by: Kai Huang <ahkcs@amazon.com>
1 parent 4b4217e commit 0ff7d97

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,8 +2423,12 @@ public RelNode visitReplace(Replace node, CalcitePlanContext context) {
24232423
Set<String> fieldsToReplace =
24242424
node.getFieldList().stream().map(f -> f.getField().toString()).collect(Collectors.toSet());
24252425

2426-
// Validate that all fields to replace exist in the current schema
2427-
validateFieldsExist(fieldsToReplace, fieldNames);
2426+
// Validate that all fields to replace exist by calling field() on each
2427+
// This leverages relBuilder.field()'s built-in validation which throws
2428+
// IllegalArgumentException if any field doesn't exist
2429+
for (String fieldToReplace : fieldsToReplace) {
2430+
context.relBuilder.field(fieldToReplace);
2431+
}
24282432

24292433
List<RexNode> projectList = new ArrayList<>();
24302434

@@ -2454,16 +2458,6 @@ public RelNode visitReplace(Replace node, CalcitePlanContext context) {
24542458
return context.relBuilder.peek();
24552459
}
24562460

2457-
private void validateFieldsExist(Set<String> fieldsToValidate, List<String> availableFields) {
2458-
Set<String> availableFieldsSet = new HashSet<>(availableFields);
2459-
for (String field : fieldsToValidate) {
2460-
if (!availableFieldsSet.contains(field)) {
2461-
throw new IllegalArgumentException(
2462-
String.format("field [%s] not found; input fields are: %s", field, availableFields));
2463-
}
2464-
}
2465-
}
2466-
24672461
private void buildParseRelNode(Parse node, CalcitePlanContext context) {
24682462
RexNode sourceField = rexVisitor.analyze(node.getSourceField(), context);
24692463
ParseMethod parseMethod = node.getParseMethod();

0 commit comments

Comments
 (0)