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

Remove use of legacy mappings from PostgreSQL connector #6366

Merged
merged 4 commits into from
Dec 17, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
import static io.prestosql.plugin.jdbc.StandardColumnMappings.varbinaryWriteFunction;
import static io.prestosql.plugin.jdbc.StandardColumnMappings.varcharWriteFunction;
import static io.prestosql.plugin.jdbc.TypeHandlingJdbcSessionProperties.getUnsupportedTypeHandling;
import static io.prestosql.plugin.jdbc.UnsupportedTypeHandling.CONVERT_TO_VARCHAR;
import static io.prestosql.plugin.jdbc.UnsupportedTypeHandling.IGNORE;
import static io.prestosql.plugin.postgresql.PostgreSqlConfig.ArrayMapping.AS_ARRAY;
import static io.prestosql.plugin.postgresql.PostgreSqlConfig.ArrayMapping.AS_JSON;
Expand Down Expand Up @@ -471,8 +472,11 @@ public Optional<ColumnMapping> toPrestoType(ConnectorSession session, Connection
break;
}

// TODO support PostgreSQL's TIME WITH TIME ZONE explicitly, otherwise predicate pushdown for these types may be incorrect
return legacyToPrestoType(session, connection, typeHandle);
if (getUnsupportedTypeHandling(session) == CONVERT_TO_VARCHAR) {
return mapToUnboundedVarchar(typeHandle);
}

return Optional.empty();
}

private Optional<ColumnMapping> arrayToPrestoType(ConnectorSession session, Connection connection, JdbcTypeHandle typeHandle)
Expand Down Expand Up @@ -617,7 +621,8 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type)
String elementDataType = toWriteMapping(session, elementType).getDataType();
return WriteMapping.objectMapping(elementDataType + "[]", arrayWriteFunction(session, elementType, getArrayElementPgTypeName(session, this, elementType)));
}
return legacyToWriteMapping(session, type);

throw new PrestoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName());
}

@Override
Expand Down Expand Up @@ -721,7 +726,7 @@ public void setColumnComment(ConnectorSession session, JdbcTableHandle handle, J

private static ColumnMapping timestampWithTimeZoneColumnMapping(int precision)
{
// PosgreSQL supports timestamptz precision up to microseconds
// PostgreSQL supports timestamptz precision up to microseconds
checkArgument(precision <= POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION, "unsupported precision value %d", precision);
TimestampWithTimeZoneType prestoType = createTimestampWithTimeZoneType(precision);
if (precision <= TimestampWithTimeZoneType.MAX_SHORT_PRECISION) {
Expand All @@ -730,12 +735,10 @@ private static ColumnMapping timestampWithTimeZoneColumnMapping(int precision)
shortTimestampWithTimeZoneReadFunction(),
shortTimestampWithTimeZoneWriteFunction());
}
else {
return ColumnMapping.objectMapping(
prestoType,
longTimestampWithTimeZoneReadFunction(),
longTimestampWithTimeZoneWriteFunction());
}
return ColumnMapping.objectMapping(
prestoType,
longTimestampWithTimeZoneReadFunction(),
longTimestampWithTimeZoneWriteFunction());
}

private static LongReadFunction shortTimestampWithTimeZoneReadFunction()
Expand Down