diff --git a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java index 4dbf44840cd6..412b17ca31b6 100644 --- a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java +++ b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java @@ -612,13 +612,13 @@ private Optional arrayToTrinoType(ConnectorSession session, Conne } return baseElementMapping .map(elementMapping -> { - ArrayType prestoArrayType = new ArrayType(elementMapping.getType()); - ColumnMapping arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, elementMapping, baseElementTypeName); + ArrayType trinoArrayType = new ArrayType(elementMapping.getType()); + ColumnMapping arrayColumnMapping = arrayColumnMapping(session, trinoArrayType, elementMapping, baseElementTypeName); int arrayDimensions = typeHandle.getArrayDimensions().get(); for (int i = 1; i < arrayDimensions; i++) { - prestoArrayType = new ArrayType(prestoArrayType); - arrayColumnMapping = arrayColumnMapping(session, prestoArrayType, arrayColumnMapping, baseElementTypeName); + trinoArrayType = new ArrayType(trinoArrayType); + arrayColumnMapping = arrayColumnMapping(session, trinoArrayType, arrayColumnMapping, baseElementTypeName); } return arrayColumnMapping; }); @@ -1116,15 +1116,15 @@ private static ColumnMapping timestampWithTimeZoneColumnMapping(int precision) { // PostgreSQL supports timestamptz precision up to microseconds checkArgument(precision <= POSTGRESQL_MAX_SUPPORTED_TIMESTAMP_PRECISION, "unsupported precision value %s", precision); - TimestampWithTimeZoneType prestoType = createTimestampWithTimeZoneType(precision); + TimestampWithTimeZoneType trinoType = createTimestampWithTimeZoneType(precision); if (precision <= TimestampWithTimeZoneType.MAX_SHORT_PRECISION) { return ColumnMapping.longMapping( - prestoType, + trinoType, shortTimestampWithTimeZoneReadFunction(), shortTimestampWithTimeZoneWriteFunction()); } return ColumnMapping.objectMapping( - prestoType, + trinoType, longTimestampWithTimeZoneReadFunction(), longTimestampWithTimeZoneWriteFunction()); } diff --git a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/TypeUtils.java b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/TypeUtils.java index 642a9cb52a5b..10e6059f9cb5 100644 --- a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/TypeUtils.java +++ b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/TypeUtils.java @@ -118,7 +118,7 @@ static Object[] getJdbcObjectArray(ConnectorSession session, Type elementType, B Object[] valuesArray = new Object[positionCount]; int subArrayLength = 1; for (int i = 0; i < positionCount; i++) { - Object objectValue = prestoNativeToJdbcObject(session, elementType, readNativeValue(elementType, block, i)); + Object objectValue = trinoNativeToJdbcObject(session, elementType, readNativeValue(elementType, block, i)); valuesArray[i] = objectValue; if (objectValue != null && objectValue.getClass().isArray()) { subArrayLength = Math.max(subArrayLength, Array.getLength(objectValue)); @@ -154,62 +154,62 @@ private static void handleArrayNulls(Object[] valuesArray, int length) } } - private static Object prestoNativeToJdbcObject(ConnectorSession session, Type prestoType, Object prestoNative) + private static Object trinoNativeToJdbcObject(ConnectorSession session, Type trinoType, Object trinoNative) throws SQLException { - if (prestoNative == null) { + if (trinoNative == null) { return null; } - if (DOUBLE.equals(prestoType) || BOOLEAN.equals(prestoType) || BIGINT.equals(prestoType)) { - return prestoNative; + if (DOUBLE.equals(trinoType) || BOOLEAN.equals(trinoType) || BIGINT.equals(trinoType)) { + return trinoNative; } - if (prestoType instanceof DecimalType) { - DecimalType decimalType = (DecimalType) prestoType; + if (trinoType instanceof DecimalType) { + DecimalType decimalType = (DecimalType) trinoType; if (decimalType.isShort()) { - BigInteger unscaledValue = BigInteger.valueOf((long) prestoNative); + BigInteger unscaledValue = BigInteger.valueOf((long) trinoNative); return new BigDecimal(unscaledValue, decimalType.getScale(), new MathContext(decimalType.getPrecision())); } - BigInteger unscaledValue = ((Int128) prestoNative).toBigInteger(); + BigInteger unscaledValue = ((Int128) trinoNative).toBigInteger(); return new BigDecimal(unscaledValue, decimalType.getScale(), new MathContext(decimalType.getPrecision())); } - if (REAL.equals(prestoType)) { - return intBitsToFloat(toIntExact((long) prestoNative)); + if (REAL.equals(trinoType)) { + return intBitsToFloat(toIntExact((long) trinoNative)); } - if (TINYINT.equals(prestoType)) { - return SignedBytes.checkedCast((long) prestoNative); + if (TINYINT.equals(trinoType)) { + return SignedBytes.checkedCast((long) trinoNative); } - if (SMALLINT.equals(prestoType)) { - return Shorts.checkedCast((long) prestoNative); + if (SMALLINT.equals(trinoType)) { + return Shorts.checkedCast((long) trinoNative); } - if (INTEGER.equals(prestoType)) { - return toIntExact((long) prestoNative); + if (INTEGER.equals(trinoType)) { + return toIntExact((long) trinoNative); } - if (DATE.equals(prestoType)) { + if (DATE.equals(trinoType)) { // convert to midnight in default time zone - long millis = DAYS.toMillis((long) prestoNative); + long millis = DAYS.toMillis((long) trinoNative); return new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millis)); } - if (prestoType instanceof TimestampType && ((TimestampType) prestoType).isShort()) { - return toPgTimestamp(fromTrinoTimestamp((long) prestoNative)); + if (trinoType instanceof TimestampType && ((TimestampType) trinoType).isShort()) { + return toPgTimestamp(fromTrinoTimestamp((long) trinoNative)); } - if (prestoType instanceof TimestampWithTimeZoneType) { + if (trinoType instanceof TimestampWithTimeZoneType) { // PostgreSQL does not store zone, only the point in time - int precision = ((TimestampWithTimeZoneType) prestoType).getPrecision(); + int precision = ((TimestampWithTimeZoneType) trinoType).getPrecision(); if (precision <= TimestampWithTimeZoneType.MAX_SHORT_PRECISION) { - long millisUtc = unpackMillisUtc((long) prestoNative); + long millisUtc = unpackMillisUtc((long) trinoNative); return new Timestamp(millisUtc); } else { - LongTimestampWithTimeZone value = (LongTimestampWithTimeZone) prestoNative; + LongTimestampWithTimeZone value = (LongTimestampWithTimeZone) trinoNative; long epochSeconds = floorDiv(value.getEpochMillis(), MILLISECONDS_PER_SECOND); long nanosOfSecond = floorMod(value.getEpochMillis(), MILLISECONDS_PER_SECOND) * NANOSECONDS_PER_MILLISECOND + value.getPicosOfMilli() / PICOSECONDS_PER_NANOSECOND; @@ -217,16 +217,16 @@ private static Object prestoNativeToJdbcObject(ConnectorSession session, Type pr } } - if (prestoType instanceof VarcharType || prestoType instanceof CharType) { - return ((Slice) prestoNative).toStringUtf8(); + if (trinoType instanceof VarcharType || trinoType instanceof CharType) { + return ((Slice) trinoNative).toStringUtf8(); } - if (prestoType instanceof ArrayType) { + if (trinoType instanceof ArrayType) { // process subarray of multi-dimensional array - return getJdbcObjectArray(session, ((ArrayType) prestoType).getElementType(), (Block) prestoNative); + return getJdbcObjectArray(session, ((ArrayType) trinoType).getElementType(), (Block) trinoNative); } - throw new TrinoException(NOT_SUPPORTED, "Unsupported type: " + prestoType); + throw new TrinoException(NOT_SUPPORTED, "Unsupported type: " + trinoType); } static PGobject toPgTimestamp(LocalDateTime localDateTime)