Skip to content

Commit 7d6805f

Browse files
author
Julien Ruaux
committed
refactor: replaced code that's only available with java 16
1 parent 05fccd7 commit 7d6805f

7 files changed

+34
-28
lines changed

src/main/java/com/redis/trino/RediSearchMetadata.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.OptionalLong;
4242
import java.util.Set;
4343
import java.util.concurrent.atomic.AtomicReference;
44+
import java.util.stream.Collectors;
4445
import java.util.stream.IntStream;
4546

4647
import com.google.common.collect.ImmutableList;
@@ -212,7 +213,7 @@ public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, Con
212213
setRollback(() -> rediSearchSession.dropTable(tableMetadata.getTable()));
213214

214215
return new RediSearchOutputTableHandle(tableMetadata.getTable(),
215-
columns.stream().filter(c -> !c.isHidden()).toList());
216+
columns.stream().filter(c -> !c.isHidden()).collect(Collectors.toList()));
216217
}
217218

218219
@Override
@@ -233,7 +234,7 @@ public ConnectorInsertTableHandle beginInsert(ConnectorSession session, Connecto
233234
List<RediSearchColumnHandle> columns = rediSearchSession.getTable(table.getSchemaTableName()).getColumns();
234235

235236
return new RediSearchInsertTableHandle(table.getSchemaTableName(),
236-
columns.stream().filter(column -> !column.isHidden()).toList());
237+
columns.stream().filter(column -> !column.isHidden()).collect(Collectors.toList()));
237238
}
238239

239240
@Override
@@ -293,8 +294,8 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
293294
escape = Optional.of((Slice) (((Constant) arguments.get(2)).getValue()));
294295
}
295296

296-
if (!newWildcards.containsKey(columnName) && pattern instanceof Slice slice) {
297-
String wildcard = likeToWildcard(slice, escape);
297+
if (!newWildcards.containsKey(columnName) && pattern instanceof Slice) {
298+
String wildcard = likeToWildcard((Slice) pattern, escape);
298299
if (column.getFieldType() == Field.Type.TAG) {
299300
wildcard = Values.tags(wildcard).toString();
300301
}
@@ -477,14 +478,15 @@ private SchemaTableName getTableName(ConnectorTableHandle tableHandle) {
477478
private ConnectorTableMetadata getTableMetadata(ConnectorSession session, SchemaTableName tableName) {
478479
RediSearchTableHandle tableHandle = rediSearchSession.getTable(tableName).getTableHandle();
479480

480-
List<ColumnMetadata> columns = ImmutableList.copyOf(getColumnHandles(session, tableHandle).values().stream()
481-
.map(RediSearchColumnHandle.class::cast).map(RediSearchColumnHandle::toColumnMetadata).toList());
481+
List<ColumnMetadata> columns = ImmutableList
482+
.copyOf(getColumnHandles(session, tableHandle).values().stream().map(RediSearchColumnHandle.class::cast)
483+
.map(RediSearchColumnHandle::toColumnMetadata).collect(Collectors.toList()));
482484

483485
return new ConnectorTableMetadata(tableName, columns);
484486
}
485487

486488
private List<RediSearchColumnHandle> buildColumnHandles(ConnectorTableMetadata tableMetadata) {
487489
return tableMetadata.getColumns().stream().map(m -> new RediSearchColumnHandle(m.getName(), m.getType(),
488-
RediSearchSession.toFieldType(m.getType()), m.isHidden(), true)).toList();
490+
RediSearchSession.toFieldType(m.getType()), m.isHidden(), true)).collect(Collectors.toList());
489491
}
490492
}

src/main/java/com/redis/trino/RediSearchPageSink.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ private String getObjectValue(Type type, Block block, int position) {
140140
if (type instanceof VarcharType) {
141141
return type.getSlice(block, position).toStringUtf8();
142142
}
143-
if (type instanceof CharType charType) {
144-
return padSpaces(type.getSlice(block, position), charType).toStringUtf8();
143+
if (type instanceof CharType) {
144+
return padSpaces(type.getSlice(block, position), (CharType) type).toStringUtf8();
145145
}
146146
if (type.equals(VarbinaryType.VARBINARY)) {
147147
return new String(type.getSlice(block, position).getBytes());
@@ -162,8 +162,8 @@ private String getObjectValue(Type type, Block block, int position) {
162162
long millisUtc = unpackMillisUtc(type.getLong(block, position));
163163
return String.valueOf(millisUtc);
164164
}
165-
if (type instanceof DecimalType decimalType) {
166-
return readBigDecimal(decimalType, block, position).toPlainString();
165+
if (type instanceof DecimalType) {
166+
return readBigDecimal((DecimalType) type, block, position).toPlainString();
167167
}
168168
throw new TrinoException(NOT_SUPPORTED, "unsupported type: " + type);
169169
}

src/main/java/com/redis/trino/RediSearchPageSource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.OutputStream;
3030
import java.util.Iterator;
3131
import java.util.List;
32+
import java.util.stream.Collectors;
3233

3334
import com.fasterxml.jackson.core.JsonFactory;
3435
import com.fasterxml.jackson.core.JsonGenerator;
@@ -57,8 +58,8 @@ public class RediSearchPageSource implements ConnectorPageSource {
5758

5859
public RediSearchPageSource(RediSearchSession rediSearchSession, RediSearchTableHandle tableHandle,
5960
List<RediSearchColumnHandle> columns) {
60-
this.columnNames = columns.stream().map(RediSearchColumnHandle::getName).toList();
61-
this.columnTypes = columns.stream().map(RediSearchColumnHandle::getType).toList();
61+
this.columnNames = columns.stream().map(RediSearchColumnHandle::getName).collect(Collectors.toList());
62+
this.columnTypes = columns.stream().map(RediSearchColumnHandle::getType).collect(Collectors.toList());
6263
this.cursor = rediSearchSession.search(tableHandle, columns).iterator();
6364
this.currentDoc = null;
6465
this.pageBuilder = new PageBuilder(columnTypes);

src/main/java/com/redis/trino/RediSearchPageSourceAggregate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Iterator;
3131
import java.util.List;
3232
import java.util.Map;
33+
import java.util.stream.Collectors;
3334

3435
import com.fasterxml.jackson.core.JsonFactory;
3536
import com.fasterxml.jackson.core.JsonGenerator;
@@ -62,8 +63,8 @@ public class RediSearchPageSourceAggregate implements ConnectorPageSource {
6263
public RediSearchPageSourceAggregate(RediSearchSession rediSearchSession, RediSearchTableHandle tableHandle,
6364
List<RediSearchColumnHandle> columns) {
6465
this.iterator = new CursorIterator(rediSearchSession, tableHandle);
65-
this.columnNames = columns.stream().map(RediSearchColumnHandle::getName).toList();
66-
this.columnTypes = columns.stream().map(RediSearchColumnHandle::getType).toList();
66+
this.columnNames = columns.stream().map(RediSearchColumnHandle::getName).collect(Collectors.toList());
67+
this.columnTypes = columns.stream().map(RediSearchColumnHandle::getType).collect(Collectors.toList());
6768
this.currentDoc = null;
6869
this.pageBuilder = new PageBuilder(columnTypes);
6970
}

src/main/java/com/redis/trino/RediSearchPageSourceResultWriter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ private long getLong(Type type, String value) {
9090
if (type.equals(REAL)) {
9191
return floatToIntBits((Float.parseFloat(value)));
9292
}
93-
if (type instanceof DecimalType decimalType) {
94-
return encodeShortScaledValue(new BigDecimal(value), decimalType.getScale());
93+
if (type instanceof DecimalType) {
94+
return encodeShortScaledValue(new BigDecimal(value), ((DecimalType) type).getScale());
9595
}
9696
if (type.equals(DATE)) {
9797
return LocalDate.from(DateTimeFormatter.ISO_DATE.parse(value)).toEpochDay();
@@ -109,10 +109,10 @@ private long getLong(Type type, String value) {
109109
private void writeSlice(BlockBuilder output, Type type, String value) {
110110
if (type instanceof VarcharType) {
111111
type.writeSlice(output, utf8Slice(value));
112-
} else if (type instanceof CharType charType) {
113-
type.writeSlice(output, truncateToLengthAndTrimSpaces(utf8Slice(value), charType));
114-
} else if (type instanceof DecimalType decimalType) {
115-
type.writeObject(output, encodeScaledValue(new BigDecimal(value), decimalType.getScale()));
112+
} else if (type instanceof CharType) {
113+
type.writeSlice(output, truncateToLengthAndTrimSpaces(utf8Slice(value), (CharType) type));
114+
} else if (type instanceof DecimalType) {
115+
type.writeObject(output, encodeScaledValue(new BigDecimal(value), ((DecimalType) type).getScale()));
116116
} else if (type.getBaseName().equals(JSON)) {
117117
type.writeSlice(output, io.trino.plugin.base.util.JsonTypeUtil.jsonParse(utf8Slice(value)));
118118
} else {

src/main/java/com/redis/trino/RediSearchQueryBuilder.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Optional;
4040
import java.util.Set;
4141
import java.util.function.BiFunction;
42+
import java.util.stream.Collectors;
4243

4344
import com.google.common.collect.Iterables;
4445
import com.google.common.primitives.Primitives;
@@ -123,8 +124,8 @@ private Optional<Node> buildPredicate(RediSearchColumnHandle column, Domain doma
123124
List<Value> rangeConjuncts = new ArrayList<>();
124125
if (!range.isLowUnbounded()) {
125126
Object translated = translateValue(range.getLowBoundedValue(), column.getType());
126-
if (translated instanceof Number numericValue) {
127-
double doubleValue = numericValue.doubleValue();
127+
if (translated instanceof Number) {
128+
double doubleValue = ((Number) translated).doubleValue();
128129
rangeConjuncts.add(range.isLowInclusive() ? Values.ge(doubleValue) : Values.gt(doubleValue));
129130
} else {
130131
throw new UnsupportedOperationException(
@@ -134,8 +135,8 @@ private Optional<Node> buildPredicate(RediSearchColumnHandle column, Domain doma
134135
}
135136
if (!range.isHighUnbounded()) {
136137
Object translated = translateValue(range.getHighBoundedValue(), column.getType());
137-
if (translated instanceof Number numericValue) {
138-
double doubleValue = numericValue.doubleValue();
138+
if (translated instanceof Number) {
139+
double doubleValue = ((Number) translated).doubleValue();
139140
rangeConjuncts.add(range.isHighInclusive() ? Values.le(doubleValue) : Values.lt(doubleValue));
140141
} else {
141142
throw new UnsupportedOperationException(
@@ -228,9 +229,9 @@ public Optional<Group> group(RediSearchTableHandle table) {
228229
List<MetricAggregation> aggregates = table.getMetricAggregations();
229230
List<String> groupFields = new ArrayList<>();
230231
if (terms != null && !terms.isEmpty()) {
231-
groupFields = terms.stream().map(TermAggregation::getTerm).toList();
232+
groupFields = terms.stream().map(TermAggregation::getTerm).collect(Collectors.toList());
232233
}
233-
List<Reducer> reducers = aggregates.stream().map(this::reducer).toList();
234+
List<Reducer> reducers = aggregates.stream().map(this::reducer).collect(Collectors.toList());
234235
if (reducers.isEmpty()) {
235236
return Optional.empty();
236237
}

src/main/java/com/redis/trino/RediSearchSession.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Optional;
3939
import java.util.Set;
4040
import java.util.concurrent.TimeUnit;
41+
import java.util.stream.Collectors;
4142

4243
import com.google.common.cache.CacheBuilder;
4344
import com.google.common.cache.CacheLoader;
@@ -177,7 +178,7 @@ public void createTable(SchemaTableName schemaTableName, List<RediSearchColumnHa
177178
String tableName = schemaTableName.getTableName();
178179
if (!connection.sync().ftList().contains(tableName)) {
179180
List<Field<String>> fields = columns.stream().filter(c -> !c.getName().equals("_id"))
180-
.map(c -> buildField(c.getName(), c.getType())).toList();
181+
.map(c -> buildField(c.getName(), c.getType())).collect(Collectors.toList());
181182
CreateOptions.Builder<String, String> options = CreateOptions.<String, String>builder();
182183
options.prefix(tableName + ":");
183184
connection.sync().ftCreate(tableName, options.build(), fields.toArray(Field[]::new));

0 commit comments

Comments
 (0)