Skip to content

Commit 6e9fd4f

Browse files
committed
Downgrade langauge level to java 11
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 4f94859 commit 6e9fd4f

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
}
@@ -660,36 +660,47 @@ private static AutoDateHistogramAggregationBuilder analyzeAutoDateSpan(
660660
}
661661

662662
private static boolean isAutoDateSpan(RexNode rex) {
663-
return rex instanceof RexCall rexCall
664-
&& rexCall.getKind() == SqlKind.OTHER_FUNCTION
665-
&& rexCall.getOperator().equals(WIDTH_BUCKET);
663+
if (rex instanceof RexCall) {
664+
RexCall rexCall = (RexCall) rex;
665+
return rexCall.getKind() == SqlKind.OTHER_FUNCTION
666+
&& rexCall.getOperator().equals(WIDTH_BUCKET);
667+
}
668+
return false;
666669
}
667670

668671
private static boolean isCase(RexNode rex) {
669-
return rex instanceof RexCall rexCall && rexCall.getKind() == SqlKind.CASE;
672+
if (rex instanceof RexCall) {
673+
RexCall rexCall = (RexCall) rex;
674+
return rexCall.getKind() == SqlKind.CASE;
675+
}
676+
return false;
670677
}
671678

672679
private static CompositeValuesSourceBuilder<?> createCompositeBucket(
673680
Integer groupIndex, Project project, AggregateAnalyzer.AggregateBuilderHelper helper) {
674681
RexNode rex = project.getProjects().get(groupIndex);
675682
String bucketName = project.getRowType().getFieldNames().get(groupIndex);
676-
if (rex instanceof RexCall rexCall
677-
&& rexCall.getKind() == SqlKind.OTHER_FUNCTION
678-
&& rexCall.getOperator().getName().equalsIgnoreCase(BuiltinFunctionName.SPAN.name())
679-
&& rexCall.getOperands().size() == 3
680-
&& rexCall.getOperands().get(0) instanceof RexInputRef rexInputRef
681-
&& rexCall.getOperands().get(1) instanceof RexLiteral valueLiteral
682-
&& rexCall.getOperands().get(2) instanceof RexLiteral unitLiteral) {
683-
return CompositeAggregationBuilder.buildHistogram(
684-
bucketName,
685-
helper.inferNamedField(((RexCall) rex).getOperands().get(0)).getRootName(),
686-
((RexLiteral)((RexCall) rex).getOperands().get(1)).getValueAs(Double.class),
687-
SpanUnit.of(((RexLiteral)((RexCall) rex).getOperands().get(2)).getValueAs(String.class)),
688-
MissingOrder.FIRST,
689-
helper.bucketNullable);
690-
} else {
691-
return createTermsSourceBuilder(bucketName, rex, helper);
683+
if (rex instanceof RexCall) {
684+
RexCall rexCall = (RexCall) rex;
685+
if (rexCall.getKind() == SqlKind.OTHER_FUNCTION
686+
&& rexCall.getOperator().getName().equalsIgnoreCase(BuiltinFunctionName.SPAN.name())
687+
&& rexCall.getOperands().size() == 3
688+
&& rexCall.getOperands().get(0) instanceof RexInputRef
689+
&& rexCall.getOperands().get(1) instanceof RexLiteral
690+
&& rexCall.getOperands().get(2) instanceof RexLiteral) {
691+
RexInputRef rexInputRef = (RexInputRef) rexCall.getOperands().get(0);
692+
RexLiteral valueLiteral = (RexLiteral) rexCall.getOperands().get(1);
693+
RexLiteral unitLiteral = (RexLiteral) rexCall.getOperands().get(2);
694+
return CompositeAggregationBuilder.buildHistogram(
695+
bucketName,
696+
helper.inferNamedField(rexInputRef).getRootName(),
697+
valueLiteral.getValueAs(Double.class),
698+
SpanUnit.of(unitLiteral.getValueAs(String.class)),
699+
MissingOrder.FIRST,
700+
helper.bucketNullable);
701+
}
692702
}
703+
return createTermsSourceBuilder(bucketName, rex, helper);
693704
}
694705

695706
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)