Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set air.compiler.fail-warnings as true in Redis and remove deprecated DateTimeUtils.parseLegacyTime #22202

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions core/trino-main/src/main/java/io/trino/util/DateTimeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import static io.trino.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
import static io.trino.sql.tree.IntervalLiteral.IntervalField;
import static io.trino.util.DateTimeZoneIndex.getChronology;
import static io.trino.util.DateTimeZoneIndex.getDateTimeZone;
import static io.trino.util.DateTimeZoneIndex.packDateTimeWithZone;
import static java.lang.Math.toIntExact;
import static java.lang.String.format;
Expand Down Expand Up @@ -184,29 +183,6 @@ public static long convertToTimestampWithTimeZone(TimeZoneKey timeZoneKey, Strin
return packDateTimeWithZone(dateTime);
}

private static final DateTimeFormatter TIME_FORMATTER;

static {
DateTimeParser[] timeWithoutTimeZoneParser = {
DateTimeFormat.forPattern("H:m").getParser(),
DateTimeFormat.forPattern("H:m:s").getParser(),
DateTimeFormat.forPattern("H:m:s.SSS").getParser()};
DateTimePrinter timeWithoutTimeZonePrinter = DateTimeFormat.forPattern("HH:mm:ss.SSS").getPrinter();
TIME_FORMATTER = new DateTimeFormatterBuilder().append(timeWithoutTimeZonePrinter, timeWithoutTimeZoneParser).toFormatter().withZoneUTC();
}

/**
* Parse a string (without a zone) as a value of TIME type, interpreted in {@code timeZoneKey} zone.
*
* @return stack representation of legacy TIME type
* @deprecated applicable in legacy timestamp semantics only
*/
@Deprecated
public static long parseLegacyTime(TimeZoneKey timeZoneKey, String value)
{
return TIME_FORMATTER.withZone(getDateTimeZone(timeZoneKey)).parseMillis(value);
}

private static final int YEAR_FIELD = 0;
private static final int MONTH_FIELD = 1;
private static final int DAY_FIELD = 3;
Expand Down
1 change: 1 addition & 0 deletions plugin/trino-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<properties>
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
<air.compiler.fail-warnings>true</air.compiler.fail-warnings>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import io.trino.spi.connector.ConnectorTableVersion;
import io.trino.spi.connector.Constraint;
import io.trino.spi.connector.ConstraintApplicationResult;
import io.trino.spi.connector.RelationColumnsMetadata;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.connector.SchemaTablePrefix;
import io.trino.spi.connector.TableNotFoundException;
import io.trino.spi.predicate.Domain;
import io.trino.spi.predicate.Range;
Expand All @@ -42,17 +42,19 @@
import jakarta.annotation.Nullable;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;

import static io.trino.plugin.redis.RedisSplit.toRedisDataType;
import static io.trino.spi.StandardErrorCode.NOT_SUPPORTED;
import static java.util.Objects.requireNonNull;
import static io.trino.spi.connector.RelationColumnsMetadata.forTable;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
Expand Down Expand Up @@ -251,28 +253,24 @@ else if (getUserDefinedKeySize(session, handle) > 1) {
}

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
public Iterator<RelationColumnsMetadata> streamRelationColumns(
ConnectorSession session,
Optional<String> schemaName,
UnaryOperator<Set<SchemaTableName>> relationFilter)
{
requireNonNull(prefix, "prefix is null");
Map<SchemaTableName, RelationColumnsMetadata> relationColumns = new HashMap<>();

ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();

List<SchemaTableName> tableNames;
if (prefix.getTable().isEmpty()) {
tableNames = listTables(session, prefix.getSchema());
}
else {
tableNames = ImmutableList.of(prefix.toSchemaTableName());
}

for (SchemaTableName tableName : tableNames) {
for (SchemaTableName tableName : listTables(session, schemaName)) {
ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
// table can disappear during listing operation
if (tableMetadata != null) {
columns.put(tableName, tableMetadata.getColumns());
relationColumns.put(tableName, forTable(tableName, tableMetadata.getColumns()));
}
}
return columns.buildOrThrow();

return relationFilter.apply(relationColumns.keySet()).stream()
.map(relationColumns::get)
.iterator();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
import io.trino.client.QueryData;
import io.trino.client.QueryStatusInfo;
import io.trino.server.testing.TestingTrinoServer;
import io.trino.spi.type.TimeZoneKey;
import io.trino.spi.type.Type;
import io.trino.spi.type.VarcharType;
import io.trino.testing.AbstractTestingTrinoClient;
import io.trino.testing.ResultsSession;
import io.trino.util.DateTimeUtils;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

Expand All @@ -37,25 +33,16 @@
import java.util.concurrent.atomic.AtomicReference;

import static com.google.common.base.Preconditions.checkState;
import static io.trino.operator.scalar.timestamp.VarcharToTimestampCast.castToShortTimestamp;
import static io.trino.spi.type.BigintType.BIGINT;
import static io.trino.spi.type.BooleanType.BOOLEAN;
import static io.trino.spi.type.DateTimeEncoding.unpackMillisUtc;
import static io.trino.spi.type.DateType.DATE;
import static io.trino.spi.type.DoubleType.DOUBLE;
import static io.trino.spi.type.IntegerType.INTEGER;
import static io.trino.spi.type.TimeType.TIME_MILLIS;
import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS;
import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS;
import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
import static io.trino.util.DateTimeUtils.parseLegacyTime;
import static java.util.Objects.requireNonNull;

public class RedisLoader
extends AbstractTestingTrinoClient<Void>
{
private static final DateTimeFormatter ISO8601_FORMATTER = ISODateTimeFormat.dateTime();

private final JedisPool jedisPool;
private final String tableName;
private final String dataFormat;
Expand All @@ -80,21 +67,14 @@ public RedisLoader(
public ResultsSession<Void> getResultSession(Session session)
{
requireNonNull(session, "session is null");
return new RedisLoadingSession(session);
return new RedisLoadingSession();
}

private class RedisLoadingSession
implements ResultsSession<Void>
{
private final AtomicReference<List<Type>> types = new AtomicReference<>();

private final TimeZoneKey timeZoneKey;

private RedisLoadingSession(Session session)
{
this.timeZoneKey = session.getTimeZoneKey();
}

@Override
public void addResults(QueryStatusInfo statusInfo, QueryData data)
{
Expand Down Expand Up @@ -165,15 +145,6 @@ private Object convertValue(Object value, Type type)
if (DATE.equals(type)) {
return value;
}
if (TIME_MILLIS.equals(type)) {
return ISO8601_FORMATTER.print(parseLegacyTime(timeZoneKey, (String) value));
}
if (TIMESTAMP_MILLIS.equals(type)) {
return ISO8601_FORMATTER.print(castToShortTimestamp(TIMESTAMP_MILLIS.getPrecision(), (String) value));
}
if (TIME_TZ_MILLIS.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) {
return ISO8601_FORMATTER.print(unpackMillisUtc(DateTimeUtils.convertToTimestampWithTimeZone(timeZoneKey, (String) value)));
}
throw new AssertionError("unhandled type: " + type);
}
}
Expand Down
Loading