Skip to content

Commit 8a47056

Browse files
authored
[Feature][scaleph-engine-sql-gateway] optimize Flink TimestampData and DecimalData format (#619)
feature: optimize Flink TimestampData and DecimalData format
1 parent a185e9f commit 8a47056

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

scaleph-engine/scaleph-engine-sql-gateway/src/main/java/cn/sliew/scaleph/engine/sql/gateway/services/dto/WsFlinkSqlGatewayQueryResultDTO.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import org.apache.commons.codec.binary.Hex;
2525
import org.apache.flink.table.api.ResultKind;
2626
import org.apache.flink.table.catalog.Column;
27-
import org.apache.flink.table.data.ArrayData;
28-
import org.apache.flink.table.data.MapData;
29-
import org.apache.flink.table.data.RowData;
27+
import org.apache.flink.table.data.*;
3028
import org.apache.flink.table.gateway.api.results.ResultSet;
3129
import org.apache.flink.table.types.logical.*;
3230

@@ -128,8 +126,9 @@ private static Object getDataFromRow(Object rowData, LogicalType logicalType, in
128126
return dataClass.getDeclaredMethod("getDouble", int.class).invoke(rowData, index);
129127
case DECIMAL:
130128
DecimalType decimalType = (DecimalType) logicalType;
131-
return dataClass.getDeclaredMethod("getDecimal", int.class, int.class, int.class)
129+
DecimalData decimalData = (DecimalData) dataClass.getDeclaredMethod("getDecimal", int.class, int.class, int.class)
132130
.invoke(rowData, index, decimalType.getPrecision(), decimalType.getScale());
131+
return decimalData.toBigDecimal().doubleValue();
133132
case BIGINT:
134133
case INTERVAL_DAY_TIME:
135134
return dataClass.getDeclaredMethod("getLong", int.class).invoke(rowData, index);
@@ -178,7 +177,8 @@ private static Object getDataFromRow(Object rowData, LogicalType logicalType, in
178177
return list;
179178
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
180179
case TIMESTAMP_WITHOUT_TIME_ZONE:
181-
return dataClass.getDeclaredMethod("getTimestamp", int.class, int.class).invoke(rowData, index, ((TimestampType) logicalType).getPrecision());
180+
TimestampData timestampData = (TimestampData) dataClass.getDeclaredMethod("getTimestamp", int.class, int.class).invoke(rowData, index, ((TimestampType) logicalType).getPrecision());
181+
return timestampData.toTimestamp();
182182
case DISTINCT_TYPE:
183183
DistinctType distinctType = (DistinctType) logicalType;
184184
LogicalType sourceType = distinctType.getSourceType();

tools/docker/mysql/init.d/scaleph-ws-mysql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ VALUES (4, 6, '1.17.1',
112112
INSERT INTO `ws_flink_artifact_sql` (`id`, `flink_artifact_id`, `flink_version`, `script`, `current`, `creator`,
113113
`editor`)
114114
VALUES (5, 7, '1.17.1',
115-
'CREATE CATALOG my_catalog WITH (\n \'type\' = \'generic_in_memory\'\n);\n\nCREATE DATABASE my_catalog.my_database;\n\n\nCREATE TABLE my_catalog.my_database.source_table (\n `id` bigint,\n `name` string,\n `age` int,\n `address` string,\n `create_time`TIMESTAMP(3),\n `update_time`TIMESTAMP(3),\n WATERMARK FOR `update_time` AS update_time - INTERVAL \'1\' MINUTE\n)\nCOMMENT \'\'\nWITH (\n \'connector\' = \'datagen\',\n \'number-of-rows\' = \'100000\'\n);\n\nSELECT * FROM my_catalog.my_database.source_table;',
115+
'CREATE CATALOG my_catalog WITH (\n \'type\' = \'generic_in_memory\'\n);\n\nCREATE DATABASE my_catalog.my_database;\n\n\nCREATE TABLE my_catalog.my_database.source_table (\n `id` bigint,\n `name` string,\n `age` int,\n `address` string,\n `money` decimal(64, 4),\n `create_time`TIMESTAMP(3),\n `update_time`TIMESTAMP(3),\n WATERMARK FOR `update_time` AS update_time - INTERVAL \'1\' MINUTE\n)\nCOMMENT \'\'\nWITH (\n \'connector\' = \'datagen\',\n \'number-of-rows\' = \'100000\'\n);\n\nSELECT * FROM my_catalog.my_database.source_table;',
116116
'1', 'sys', 'sys');
117117

118118
INSERT INTO `ws_flink_artifact_sql` (`id`, `flink_artifact_id`, `flink_version`, `script`, `current`, `creator`,

0 commit comments

Comments
 (0)