Skip to content

Commit 79e2326

Browse files
committed
Downgrade langauge level to java 11
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 1b8a462 commit 79e2326

5 files changed

Lines changed: 280 additions & 277 deletions

File tree

opensearch/src/main/java/org/opensearch/sql/opensearch/request/AggregateAnalyzer.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public static Pair<List<AggregationBuilder>, OpenSearchAggregationResponseParser
238238
Set<Integer> aggPushed = aggPushedAndAggBuilder.getLeft();
239239
AggregationBuilder pushedAggBuilder = aggPushedAndAggBuilder.getRight();
240240
// The group-by list after removing pushed aggregations
241-
groupList = groupList.stream().filter(i -> !aggPushed.contains(i)).toList();
241+
groupList = groupList.stream().filter(i -> !aggPushed.contains(i)).collect(Collectors.toList());
242242
if (pushedAggBuilder != null) {
243243
subBuilder = new Builder().addAggregator(pushedAggBuilder);
244244
}
@@ -667,36 +667,47 @@ private static AutoDateHistogramAggregationBuilder analyzeAutoDateSpan(
667667
}
668668

669669
private static boolean isAutoDateSpan(RexNode rex) {
670-
return rex instanceof RexCall rexCall
671-
&& rexCall.getKind() == SqlKind.OTHER_FUNCTION
672-
&& rexCall.getOperator().equals(WIDTH_BUCKET);
670+
if (rex instanceof RexCall) {
671+
RexCall rexCall = (RexCall) rex;
672+
return rexCall.getKind() == SqlKind.OTHER_FUNCTION
673+
&& rexCall.getOperator().equals(WIDTH_BUCKET);
674+
}
675+
return false;
673676
}
674677

675678
private static boolean isCase(RexNode rex) {
676-
return rex instanceof RexCall rexCall && rexCall.getKind() == SqlKind.CASE;
679+
if (rex instanceof RexCall) {
680+
RexCall rexCall = (RexCall) rex;
681+
return rexCall.getKind() == SqlKind.CASE;
682+
}
683+
return false;
677684
}
678685

679686
private static CompositeValuesSourceBuilder<?> createCompositeBucket(
680687
Integer groupIndex, Project project, AggregateAnalyzer.AggregateBuilderHelper helper) {
681688
RexNode rex = project.getProjects().get(groupIndex);
682689
String bucketName = project.getRowType().getFieldNames().get(groupIndex);
683-
if (rex instanceof RexCall rexCall
684-
&& rexCall.getKind() == SqlKind.OTHER_FUNCTION
685-
&& rexCall.getOperator().getName().equalsIgnoreCase(BuiltinFunctionName.SPAN.name())
686-
&& rexCall.getOperands().size() == 3
687-
&& rexCall.getOperands().get(0) instanceof RexInputRef rexInputRef
688-
&& rexCall.getOperands().get(1) instanceof RexLiteral valueLiteral
689-
&& rexCall.getOperands().get(2) instanceof RexLiteral unitLiteral) {
690-
return CompositeAggregationBuilder.buildHistogram(
691-
bucketName,
692-
helper.inferNamedField(((RexCall) rex).getOperands().get(0)).getRootName(),
693-
((RexLiteral)((RexCall) rex).getOperands().get(1)).getValueAs(Double.class),
694-
SpanUnit.of(((RexLiteral)((RexCall) rex).getOperands().get(2)).getValueAs(String.class)),
695-
MissingOrder.FIRST,
696-
helper.bucketNullable);
697-
} else {
698-
return createTermsSourceBuilder(bucketName, rex, helper);
690+
if (rex instanceof RexCall) {
691+
RexCall rexCall = (RexCall) rex;
692+
if (rexCall.getKind() == SqlKind.OTHER_FUNCTION
693+
&& rexCall.getOperator().getName().equalsIgnoreCase(BuiltinFunctionName.SPAN.name())
694+
&& rexCall.getOperands().size() == 3
695+
&& rexCall.getOperands().get(0) instanceof RexInputRef
696+
&& rexCall.getOperands().get(1) instanceof RexLiteral
697+
&& rexCall.getOperands().get(2) instanceof RexLiteral) {
698+
RexInputRef rexInputRef = (RexInputRef) rexCall.getOperands().get(0);
699+
RexLiteral valueLiteral = (RexLiteral) rexCall.getOperands().get(1);
700+
RexLiteral unitLiteral = (RexLiteral) rexCall.getOperands().get(2);
701+
return CompositeAggregationBuilder.buildHistogram(
702+
bucketName,
703+
helper.inferNamedField(rexInputRef).getRootName(),
704+
valueLiteral.getValueAs(Double.class),
705+
SpanUnit.of(unitLiteral.getValueAs(String.class)),
706+
MissingOrder.FIRST,
707+
helper.bucketNullable);
708+
}
699709
}
710+
return createTermsSourceBuilder(bucketName, rex, helper);
700711
}
701712

702713
private static CompositeValuesSourceBuilder<?> createTermsSourceBuilder(

opensearch/src/main/java/org/opensearch/sql/opensearch/request/CaseRangeAnalyzer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Optional<RangeAggregationBuilder> analyze(RexCall caseCall) {
8686
}
8787

8888
// Check ELSE clause
89-
RexNode elseExpr = operands.getLast();
89+
RexNode elseExpr = operands.get(operands.size() - 1);
9090
String elseKey;
9191
if (RexLiteral.isNullLiteral(elseExpr)) {
9292
// range key doesn't support values of type: VALUE_NULL
@@ -168,20 +168,20 @@ private void analyzeSimpleComparison(RexCall call, String key) {
168168
throwUnsupported("Cannot parse value for comparison");
169169
}
170170
switch (operator.getKind()) {
171-
case GREATER_THAN_OR_EQUAL -> {
171+
case GREATER_THAN_OR_EQUAL:
172172
addFrom(key, value);
173-
}
174-
case LESS_THAN -> {
173+
break;
174+
case LESS_THAN:
175175
addTo(key, value);
176-
}
177-
default -> throw new UnsupportedOperationException(
178-
"ranges must be equivalents of field >= constant or field < constant");
176+
break;
177+
default:
178+
throw new UnsupportedOperationException(
179+
"ranges must be equivalents of field >= constant or field < constant");
179180
}
180-
;
181181
}
182182

183183
private void analyzeSearchCondition(RexCall searchCall, String key) {
184-
RexNode field = searchCall.getOperands().getFirst();
184+
RexNode field = searchCall.getOperands().get(0);
185185
if (!(field instanceof RexInputRef)) {
186186
throwUnsupported("Range query must be performed on a field");
187187
}
@@ -191,7 +191,7 @@ private void analyzeSearchCondition(RexCall searchCall, String key) {
191191
} else if (!Objects.equals(builder.field(), fieldName)) {
192192
throwUnsupported("Range query must be performed on the same field");
193193
}
194-
RexLiteral literal = (RexLiteral) searchCall.getOperands().getLast();
194+
RexLiteral literal = (RexLiteral) searchCall.getOperands().get(searchCall.getOperands().size() - 1);
195195
Sarg<?> sarg = Objects.requireNonNull(literal.getValueAs(Sarg.class));
196196
for (Range<?> r : sarg.rangeSet.asRanges()) {
197197
@SuppressWarnings("unchecked")

opensearch/src/main/java/org/opensearch/sql/opensearch/response/agg/BucketAggregationParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ public List<Map<String, Object>> parse(SearchHits hits) {
126126
protected Optional<Map<String, Object>> extract(
127127
MultiBucketsAggregation.Bucket bucket, String name) {
128128
Map<String, Object> extracted;
129-
if (bucket instanceof CompositeAggregation.Bucket compositeBucket) {
129+
if (bucket instanceof CompositeAggregation.Bucket) {
130+
CompositeAggregation.Bucket compositeBucket = (CompositeAggregation.Bucket) bucket;
130131
extracted = compositeBucket.getKey();
131132
} else if (bucket instanceof Range.Bucket
132133
|| bucket instanceof InternalAutoDateHistogram.Bucket

opensearch/src/test/java/org/opensearch/sql/opensearch/request/AggregateAnalyzerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.util.Map;
1919
import java.util.function.Consumer;
2020
import java.util.function.Function;
21+
import java.util.stream.Collectors;
22+
2123
import org.apache.calcite.rel.RelCollations;
2224
import org.apache.calcite.rel.RelNode;
2325
import org.apache.calcite.rel.core.Aggregate;
@@ -596,7 +598,7 @@ private Project createMockProject(List<Integer> refIndex) {
596598
rexNodes.add(ref);
597599
}
598600
List<org.apache.calcite.util.Pair<RexNode, String>> namedProjects =
599-
rexNodes.stream().map(n -> org.apache.calcite.util.Pair.of(n, n.toString())).toList();
601+
rexNodes.stream().map(n -> org.apache.calcite.util.Pair.of(n, n.toString())).collect(Collectors.toList());
600602
when(project.getProjects()).thenReturn(rexNodes);
601603
when(project.getRowType()).thenReturn(rowType);
602604
when(project.getNamedProjects()).thenReturn(namedProjects);

0 commit comments

Comments
 (0)