This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-presto.git
The following commit(s) were added to refs/heads/main by this push:
new 5668c23 [types] Support more types (#13)
5668c23 is described below
commit 5668c234a942d74727374d5e73c84f2791a81da4
Author: Jingsong Lee <[email protected]>
AuthorDate: Thu Jul 20 17:16:58 2023 +0800
[types] Support more types (#13)
---
.../org/apache/paimon/presto/PrestoPageSourceBase.java | 15 ++++++++++-----
.../apache/paimon/prestosql/PrestoSqlMetadataBase.java | 6 +++---
.../apache/paimon/prestosql/PrestoSqlPageSourceBase.java | 15 ++++++++++-----
3 files changed, 23 insertions(+), 13 deletions(-)
diff --git
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
index 5ad0b03..1a02be4 100644
---
a/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
+++
b/paimon-presto-common/src/main/java/org/apache/paimon/presto/PrestoPageSourceBase.java
@@ -60,8 +60,11 @@ import static
com.facebook.presto.common.type.Decimals.encodeShortScaledValue;
import static com.facebook.presto.common.type.Decimals.isLongDecimal;
import static com.facebook.presto.common.type.Decimals.isShortDecimal;
import static com.facebook.presto.common.type.IntegerType.INTEGER;
+import static com.facebook.presto.common.type.RealType.REAL;
+import static com.facebook.presto.common.type.SmallintType.SMALLINT;
import static com.facebook.presto.common.type.TimeType.TIME;
import static com.facebook.presto.common.type.TimestampType.TIMESTAMP;
+import static com.facebook.presto.common.type.TinyintType.TINYINT;
import static com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR;
import static io.airlift.slice.Slices.wrappedBuffer;
import static java.lang.String.format;
@@ -163,18 +166,20 @@ public abstract class PrestoPageSourceBase implements
ConnectorPageSource {
if (javaType == boolean.class) {
prestoType.writeBoolean(output, (Boolean) value);
} else if (javaType == long.class) {
- if (prestoType.equals(BIGINT)) {
+ if (prestoType.equals(BIGINT)
+ || prestoType.equals(INTEGER)
+ || prestoType.equals(TINYINT)
+ || prestoType.equals(SMALLINT)
+ || prestoType.equals(DATE)) {
prestoType.writeLong(output, ((Number) value).longValue());
- } else if (prestoType.equals(INTEGER)) {
- prestoType.writeLong(output, ((Number) value).intValue());
+ } else if (prestoType.equals(REAL)) {
+ prestoType.writeLong(output, Float.floatToIntBits((Float)
value));
} else if (prestoType instanceof DecimalType) {
Verify.verify(isShortDecimal(prestoType), "The type should be
short decimal");
DecimalType decimalType = (DecimalType) prestoType;
BigDecimal decimal = ((Decimal) value).toBigDecimal();
prestoType.writeLong(
output, encodeShortScaledValue(decimal,
decimalType.getScale()));
- } else if (prestoType.equals(DATE)) {
- prestoType.writeLong(output, (int) value);
} else if (prestoType.equals(TIMESTAMP)) {
prestoType.writeLong(output, ((Timestamp)
value).getMillisecond() * 1_000);
} else if (prestoType.equals(TIME)) {
diff --git
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlMetadataBase.java
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlMetadataBase.java
index 55d6aaf..b5a6526 100644
---
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlMetadataBase.java
+++
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlMetadataBase.java
@@ -297,7 +297,7 @@ public abstract class PrestoSqlMetadataBase implements
ConnectorMetadata {
column.getName(),
PrestoSqlTypeUtils.toPaimonType(column.getType())));
try {
catalog.alterTable(identifier, changes, false);
- } catch (Catalog.TableNotExistException e) {
+ } catch (Exception e) {
throw new RuntimeException(
format("table not exists: '%s'",
prestosqlTableHandle.getTableName()));
}
@@ -318,7 +318,7 @@ public abstract class PrestoSqlMetadataBase implements
ConnectorMetadata {
changes.add(SchemaChange.renameColumn(prestosqlColumnHandle.getColumnName(),
target));
try {
catalog.alterTable(identifier, changes, false);
- } catch (Catalog.TableNotExistException e) {
+ } catch (Exception e) {
throw new RuntimeException(
format("table not exists: '%s'",
prestosqlTableHandle.getTableName()));
}
@@ -336,7 +336,7 @@ public abstract class PrestoSqlMetadataBase implements
ConnectorMetadata {
changes.add(SchemaChange.dropColumn(prestosqlColumnHandle.getColumnName()));
try {
catalog.alterTable(identifier, changes, false);
- } catch (Catalog.TableNotExistException e) {
+ } catch (Exception e) {
throw new RuntimeException(
format("table not exists: '%s'",
prestosqlTableHandle.getTableName()));
}
diff --git
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlPageSourceBase.java
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlPageSourceBase.java
index a25d934..9cb0322 100644
---
a/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlPageSourceBase.java
+++
b/paimon-prestosql-common/src/main/java/org/apache/paimon/prestosql/PrestoSqlPageSourceBase.java
@@ -59,10 +59,13 @@ import static
io.prestosql.spi.type.DateTimeEncoding.packDateTimeWithZone;
import static io.prestosql.spi.type.DateType.DATE;
import static io.prestosql.spi.type.Decimals.encodeShortScaledValue;
import static io.prestosql.spi.type.IntegerType.INTEGER;
+import static io.prestosql.spi.type.RealType.REAL;
+import static io.prestosql.spi.type.SmallintType.SMALLINT;
import static io.prestosql.spi.type.TimeType.TIME;
import static io.prestosql.spi.type.TimeZoneKey.UTC_KEY;
import static io.prestosql.spi.type.TimestampType.TIMESTAMP;
import static
io.prestosql.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
+import static io.prestosql.spi.type.TinyintType.TINYINT;
import static java.lang.String.format;
/** PrestoSql {@link ConnectorPageSource}. */
@@ -156,16 +159,18 @@ public abstract class PrestoSqlPageSourceBase implements
ConnectorPageSource {
if (javaType == boolean.class) {
type.writeBoolean(output, (Boolean) value);
} else if (javaType == long.class) {
- if (type.equals(BIGINT)) {
+ if (type.equals(BIGINT)
+ || type.equals(INTEGER)
+ || type.equals(TINYINT)
+ || type.equals(SMALLINT)
+ || type.equals(DATE)) {
type.writeLong(output, ((Number) value).longValue());
- } else if (type.equals(INTEGER)) {
- type.writeLong(output, ((Number) value).intValue());
+ } else if (type.equals(REAL)) {
+ type.writeLong(output, Float.floatToIntBits((Float) value));
} else if (type instanceof DecimalType) {
DecimalType decimalType = (DecimalType) type;
BigDecimal decimal = ((Decimal) value).toBigDecimal();
type.writeLong(output, encodeShortScaledValue(decimal,
decimalType.getScale()));
- } else if (type.equals(DATE)) {
- type.writeLong(output, (int) value);
} else if (type.equals(TIMESTAMP)) {
type.writeLong(output, ((Timestamp) value).getMillisecond());
} else if (type.equals(TIME)) {