wuchong commented on a change in pull request #11538: [FLINK-16813][jdbc]  
JDBCInputFormat doesn't correctly map Short
URL: https://github.com/apache/flink/pull/11538#discussion_r401437686
 
 

 ##########
 File path: 
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/source/row/converter/PostgresRowConverter.java
 ##########
 @@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.api.java.io.jdbc.source.row.converter;
+
+import org.apache.flink.table.types.logical.ArrayType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.types.Row;
+
+import org.postgresql.jdbc.PgArray;
+import org.postgresql.util.PGobject;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * Row converter for Postgres.
+ */
+public class PostgresRowConverter extends AbstractJDBCRowConverter {
+
+       public PostgresRowConverter(RowType rowType) {
+               super(rowType);
+       }
+
+       @Override
+       public Row setRow(ResultSet resultSet, Row reuse) throws SQLException {
+               for (int pos = 0; pos < rowType.getFieldCount(); pos++) {
+                       LogicalType logicalType = rowType.getTypeAt(pos);
+                       LogicalTypeRoot root = logicalType.getTypeRoot();
+                       Object v = resultSet.getObject(pos + 1);
+
+                       if (root == LogicalTypeRoot.SMALLINT) {
+                               reuse.setField(pos, ((Integer) v).shortValue());
+                       } else if (root == LogicalTypeRoot.ARRAY) {
+
+                               ArrayType arrayType = (ArrayType) logicalType;
+                               LogicalTypeRoot elemType = 
arrayType.getElementType().getTypeRoot();
+
+                               PgArray pgArray = (PgArray) v;
+
+                               if (elemType == LogicalTypeRoot.VARBINARY) {
 
 Review comment:
   It mixes runtime and pre-flight phase. This is exactly what we wanted to 
avoid. During runtime, it should not be necessary to use `LogicalType` or 
`LogicalTypeRoot` at all. Instead, runtime converters should already be in 
place that simply perform conversion without going through big switch/case 
statements. Besides, it will be tricky to handle nested structures, e.g. 
`Array<SMALLINT>`. Could you take 
`JsonRowDeserializationSchema#createConverter` as an example?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to