Skip to content

Commit 597237e

Browse files
author
Julien Ruaux
committed
fix: Case insensitive names
Fixes #10
1 parent ad9106c commit 597237e

File tree

8 files changed

+198
-42
lines changed

8 files changed

+198
-42
lines changed

pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
</developers>
5656
<dependencies>
5757

58+
<dependency>
59+
<groupId>io.trino</groupId>
60+
<artifactId>trino-collect</artifactId>
61+
<version>${project.parent.version}</version>
62+
</dependency>
63+
5864
<dependency>
5965
<groupId>io.trino</groupId>
6066
<artifactId>trino-plugin-toolkit</artifactId>
@@ -181,13 +187,6 @@
181187
<scope>test</scope>
182188
</dependency>
183189

184-
<dependency>
185-
<groupId>io.trino</groupId>
186-
<artifactId>trino-collect</artifactId>
187-
<version>${project.parent.version}</version>
188-
<scope>test</scope>
189-
</dependency>
190-
191190
<dependency>
192191
<groupId>io.trino</groupId>
193192
<artifactId>trino-geospatial-toolkit</artifactId>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public RediSearchTableHandle beginUpdate(ConnectorSession session, ConnectorTabl
275275
List<ColumnHandle> updatedColumns, RetryMode retryMode) {
276276
checkRetry(retryMode);
277277
RediSearchTableHandle table = (RediSearchTableHandle) tableHandle;
278-
return new RediSearchTableHandle(table.getSchemaTableName(), table.getConstraint(), table.getLimit(),
279-
table.getTermAggregations(), table.getMetricAggregations(), table.getWildcards(),
278+
return new RediSearchTableHandle(table.getSchemaTableName(), table.getIndex(), table.getConstraint(),
279+
table.getLimit(), table.getTermAggregations(), table.getMetricAggregations(), table.getWildcards(),
280280
updatedColumns.stream().map(RediSearchColumnHandle.class::cast).collect(toImmutableList()));
281281
}
282282

@@ -306,7 +306,7 @@ public Optional<LimitApplicationResult<ConnectorTableHandle>> applyLimit(Connect
306306
}
307307

308308
return Optional.of(new LimitApplicationResult<>(new RediSearchTableHandle(handle.getSchemaTableName(),
309-
handle.getConstraint(), OptionalLong.of(limit), handle.getTermAggregations(),
309+
handle.getIndex(), handle.getConstraint(), OptionalLong.of(limit), handle.getTermAggregations(),
310310
handle.getMetricAggregations(), handle.getWildcards(), handle.getUpdatedColumns()), true, false));
311311
}
312312

@@ -369,7 +369,7 @@ public Optional<ConstraintApplicationResult<ConnectorTableHandle>> applyFilter(C
369369
return Optional.empty();
370370
}
371371

372-
handle = new RediSearchTableHandle(handle.getSchemaTableName(), newDomain, handle.getLimit(),
372+
handle = new RediSearchTableHandle(handle.getSchemaTableName(), handle.getIndex(), newDomain, handle.getLimit(),
373373
handle.getTermAggregations(), handle.getMetricAggregations(), newWildcards, handle.getUpdatedColumns());
374374

375375
return Optional.of(new ConstraintApplicationResult<>(handle, TupleDomain.withColumnDomains(unsupported),
@@ -495,8 +495,9 @@ public Optional<AggregationApplicationResult<ConnectorTableHandle>> applyAggrega
495495
if (aggregationList.isEmpty()) {
496496
return Optional.empty();
497497
}
498-
RediSearchTableHandle tableHandle = new RediSearchTableHandle(table.getSchemaTableName(), table.getConstraint(),
499-
table.getLimit(), terms.build(), aggregationList, table.getWildcards(), table.getUpdatedColumns());
498+
RediSearchTableHandle tableHandle = new RediSearchTableHandle(table.getSchemaTableName(), table.getIndex(),
499+
table.getConstraint(), table.getLimit(), terms.build(), aggregationList, table.getWildcards(),
500+
table.getUpdatedColumns());
500501
return Optional.of(new AggregationApplicationResult<>(tableHandle, projections.build(),
501502
resultAssignments.build(), Map.of(), false));
502503
}

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
import java.util.concurrent.TimeUnit;
4646
import java.util.stream.Collectors;
4747

48-
import com.google.common.cache.CacheBuilder;
49-
import com.google.common.cache.CacheLoader;
50-
import com.google.common.cache.LoadingCache;
48+
import com.google.common.cache.Cache;
5149
import com.google.common.collect.ImmutableList;
5250
import com.google.common.collect.ImmutableSet;
5351
import com.google.common.util.concurrent.UncheckedExecutionException;
@@ -73,6 +71,7 @@
7371
import io.lettuce.core.RedisURI;
7472
import io.lettuce.core.SslVerifyMode;
7573
import io.lettuce.core.protocol.ProtocolVersion;
74+
import io.trino.collect.cache.EvictableCacheBuilder;
7675
import io.trino.spi.HostAddress;
7776
import io.trino.spi.TrinoException;
7877
import io.trino.spi.connector.ColumnMetadata;
@@ -106,18 +105,16 @@ public class RediSearchSession {
106105
private final RediSearchTranslator translator;
107106
private final AbstractRedisClient client;
108107
private final StatefulRedisModulesConnection<String, String> connection;
109-
private final LoadingCache<SchemaTableName, RediSearchTable> tableCache;
108+
private final Cache<SchemaTableName, RediSearchTable> tableCache;
110109

111110
public RediSearchSession(TypeManager typeManager, RediSearchConfig config) {
112111
this.typeManager = requireNonNull(typeManager, "typeManager is null");
113112
this.config = requireNonNull(config, "config is null");
114113
this.translator = new RediSearchTranslator(config);
115114
this.client = client(config);
116115
this.connection = RedisModulesUtils.connection(client);
117-
this.tableCache = CacheBuilder.newBuilder().expireAfterWrite(config.getTableCacheExpiration(), TimeUnit.SECONDS)
118-
.refreshAfterWrite(config.getTableCacheRefresh(), TimeUnit.SECONDS)
119-
.build(CacheLoader.from(this::loadTableSchema));
120-
116+
this.tableCache = EvictableCacheBuilder.newBuilder()
117+
.expireAfterWrite(config.getTableCacheRefresh(), TimeUnit.SECONDS).build();
121118
}
122119

123120
private AbstractRedisClient client(RediSearchConfig config) {
@@ -194,7 +191,7 @@ public Set<String> getAllTables() {
194191

195192
@SuppressWarnings("unchecked")
196193
public void createTable(SchemaTableName schemaTableName, List<RediSearchColumnHandle> columns) {
197-
String index = index(schemaTableName);
194+
String index = schemaTableName.getTableName();
198195
if (!connection.sync().ftList().contains(index)) {
199196
List<Field<String>> fields = columns.stream().filter(c -> !RediSearchBuiltinField.isKeyColumn(c.getName()))
200197
.map(c -> buildField(c.getName(), c.getType())).collect(Collectors.toList());
@@ -266,7 +263,8 @@ private RediSearchTable loadTableSchema(SchemaTableName schemaTableName) throws
266263
fields.add(docField);
267264
}
268265
}
269-
return new RediSearchTable(new RediSearchTableHandle(schemaTableName), columns.build(), indexInfo);
266+
RediSearchTableHandle tableHandle = new RediSearchTableHandle(schemaTableName, index);
267+
return new RediSearchTable(tableHandle, columns.build(), indexInfo);
270268
}
271269

272270
private Optional<IndexInfo> indexInfo(String index) {
@@ -339,17 +337,13 @@ private boolean isGroupOperation(AggregateOperation<String, String> operation) {
339337
}
340338

341339
public AggregateWithCursorResults<String> cursorRead(RediSearchTableHandle tableHandle, long cursor) {
342-
String index = index(tableHandle.getSchemaTableName());
340+
String index = tableHandle.getIndex();
343341
if (config.getCursorCount() > 0) {
344342
return connection.sync().ftCursorRead(index, cursor, config.getCursorCount());
345343
}
346344
return connection.sync().ftCursorRead(index, cursor);
347345
}
348346

349-
private String index(SchemaTableName schemaTableName) {
350-
return schemaTableName.getTableName();
351-
}
352-
353347
private Field<String> buildField(String columnName, Type columnType) {
354348
Field.Type fieldType = toFieldType(columnType);
355349
switch (fieldType) {
@@ -427,7 +421,7 @@ private TypeSignature varcharType() {
427421
}
428422

429423
public void cursorDelete(RediSearchTableHandle tableHandle, long cursor) {
430-
connection.sync().ftCursorDelete(index(tableHandle.getSchemaTableName()), cursor);
424+
connection.sync().ftCursorDelete(tableHandle.getIndex(), cursor);
431425
}
432426

433427
public Long deleteDocs(List<String> docIds) {

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import com.fasterxml.jackson.annotation.JsonCreator;
3535
import com.fasterxml.jackson.annotation.JsonProperty;
36+
import com.google.common.base.MoreObjects;
3637
import com.google.common.collect.ImmutableList;
3738

3839
import io.trino.spi.connector.ColumnHandle;
@@ -47,6 +48,7 @@ public enum Type {
4748
}
4849

4950
private final SchemaTableName schemaTableName;
51+
private final String index;
5052
private final TupleDomain<ColumnHandle> constraint;
5153
private final OptionalLong limit;
5254
// for group by fields
@@ -56,19 +58,21 @@ public enum Type {
5658
// UPDATE only
5759
private final List<RediSearchColumnHandle> updatedColumns;
5860

59-
public RediSearchTableHandle(SchemaTableName schemaTableName) {
60-
this(schemaTableName, TupleDomain.all(), OptionalLong.empty(), Collections.emptyList(), Collections.emptyList(),
61-
Map.of(), Collections.emptyList());
61+
public RediSearchTableHandle(SchemaTableName schemaTableName, String index) {
62+
this(schemaTableName, index, TupleDomain.all(), OptionalLong.empty(), Collections.emptyList(),
63+
Collections.emptyList(), Map.of(), Collections.emptyList());
6264
}
6365

6466
@JsonCreator
6567
public RediSearchTableHandle(@JsonProperty("schemaTableName") SchemaTableName schemaTableName,
66-
@JsonProperty("constraint") TupleDomain<ColumnHandle> constraint, @JsonProperty("limit") OptionalLong limit,
68+
@JsonProperty("index") String index, @JsonProperty("constraint") TupleDomain<ColumnHandle> constraint,
69+
@JsonProperty("limit") OptionalLong limit,
6770
@JsonProperty("aggTerms") List<RediSearchAggregationTerm> termAggregations,
6871
@JsonProperty("aggregates") List<RediSearchAggregation> metricAggregations,
6972
@JsonProperty("wildcards") Map<String, String> wildcards,
7073
@JsonProperty("updatedColumns") List<RediSearchColumnHandle> updatedColumns) {
7174
this.schemaTableName = requireNonNull(schemaTableName, "schemaTableName is null");
75+
this.index = requireNonNull(index, "index is null");
7276
this.constraint = requireNonNull(constraint, "constraint is null");
7377
this.limit = requireNonNull(limit, "limit is null");
7478
this.aggregationTerms = requireNonNull(termAggregations, "aggTerms is null");
@@ -82,6 +86,11 @@ public SchemaTableName getSchemaTableName() {
8286
return schemaTableName;
8387
}
8488

89+
@JsonProperty
90+
public String getIndex() {
91+
return index;
92+
}
93+
8594
@JsonProperty
8695
public TupleDomain<ColumnHandle> getConstraint() {
8796
return constraint;
@@ -126,13 +135,14 @@ public boolean equals(Object obj) {
126135
return false;
127136
}
128137
RediSearchTableHandle other = (RediSearchTableHandle) obj;
129-
return Objects.equals(this.schemaTableName, other.schemaTableName)
138+
return Objects.equals(this.schemaTableName, other.schemaTableName) && Objects.equals(this.index, other.index)
130139
&& Objects.equals(this.constraint, other.constraint) && Objects.equals(this.limit, other.limit)
131140
&& Objects.equals(updatedColumns, other.updatedColumns);
132141
}
133142

134143
@Override
135144
public String toString() {
136-
return schemaTableName.toString();
145+
return MoreObjects.toStringHelper(this).add("schemaTableName", schemaTableName).add("index", index)
146+
.add("limit", limit).add("constraint", constraint).toString();
137147
}
138148
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public Search build() {
207207
}
208208

209209
public Search search(RediSearchTableHandle table, String[] columnNames) {
210-
String index = index(table);
210+
String index = table.getIndex();
211211
String query = queryBuilder.buildQuery(table.getConstraint(), table.getWildcards());
212212
Builder<String, String> options = SearchOptions.builder();
213213
options.withScores(true);
@@ -217,7 +217,7 @@ public Search search(RediSearchTableHandle table, String[] columnNames) {
217217
}
218218

219219
public Aggregation aggregate(RediSearchTableHandle table, String[] columnNames) {
220-
String index = index(table);
220+
String index = table.getIndex();
221221
String query = queryBuilder.buildQuery(table.getConstraint(), table.getWildcards());
222222
AggregateOptions.Builder<String, String> builder = AggregateOptions.builder();
223223
builder.load(RediSearchBuiltinField.KEY.getName());
@@ -233,10 +233,6 @@ public Aggregation aggregate(RediSearchTableHandle table, String[] columnNames)
233233
.build();
234234
}
235235

236-
private String index(RediSearchTableHandle tableHandle) {
237-
return tableHandle.getSchemaTableName().getTableName();
238-
}
239-
240236
private long limit(RediSearchTableHandle tableHandle) {
241237
if (tableHandle.getLimit().isPresent()) {
242238
return tableHandle.getLimit().getAsLong();

0 commit comments

Comments
 (0)