Biasqo commented on code in PR #171:
URL: 
https://github.com/apache/flink-connector-jdbc/pull/171#discussion_r4383687357


##########
flink-connector-jdbc-clickhouse/src/main/java/org/apache/flink/connector/jdbc/clickhouse/database/dialect/ClickHouseDialectConverter.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.connector.jdbc.clickhouse.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.GenericMapData;
+import org.apache.flink.table.data.MapData;
+import org.apache.flink.table.data.TimestampData;
+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.MapType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink 
internal object for
+ * ClickHouse.
+ */
+@Internal
+public class ClickHouseDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    public ClickHouseDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    public JdbcDeserializationConverter createInternalConverter(LogicalType 
type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createClickHouseArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.MAP) {
+            MapType mapType = (MapType) type;
+            return createClickHouseMapConverter(mapType);
+        } else {
+            return createPrimitiveConverter(type);
+        }
+    }
+
+    @Override
+    public JdbcSerializationConverter createExternalConverter(LogicalType 
type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            return (val, index, statement) ->
+                    statement.setObject(index, 
toExternalSerializer(val.getArray(index), type));
+        } else if (root == LogicalTypeRoot.MAP) {
+            return (val, index, statement) ->
+                    statement.setObject(index, 
toExternalSerializer(val.getMap(index), type));
+        } else {
+            return super.createExternalConverter(type);

Review Comment:
   Done



##########
flink-connector-jdbc-clickhouse/src/main/java/org/apache/flink/connector/jdbc/clickhouse/database/dialect/ClickHouseDialectConverter.java:
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.connector.jdbc.clickhouse.database.dialect;
+
+import org.apache.flink.annotation.Internal;
+import 
org.apache.flink.connector.jdbc.core.database.dialect.AbstractDialectConverter;
+import org.apache.flink.table.data.ArrayData;
+import org.apache.flink.table.data.DecimalData;
+import org.apache.flink.table.data.GenericArrayData;
+import org.apache.flink.table.data.GenericMapData;
+import org.apache.flink.table.data.MapData;
+import org.apache.flink.table.data.TimestampData;
+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.MapType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.logical.utils.LogicalTypeUtils;
+
+import java.lang.reflect.Array;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Runtime converter that responsible to convert between JDBC object and Flink 
internal object for
+ * ClickHouse.
+ */
+@Internal
+public class ClickHouseDialectConverter extends AbstractDialectConverter {
+
+    private static final long serialVersionUID = 1L;
+
+    public ClickHouseDialectConverter(RowType rowType) {
+        super(rowType);
+    }
+
+    @Override
+    public JdbcDeserializationConverter createInternalConverter(LogicalType 
type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            ArrayType arrayType = (ArrayType) type;
+            return createClickHouseArrayConverter(arrayType);
+        } else if (root == LogicalTypeRoot.MAP) {
+            MapType mapType = (MapType) type;
+            return createClickHouseMapConverter(mapType);
+        } else {
+            return createPrimitiveConverter(type);
+        }
+    }
+
+    @Override
+    public JdbcSerializationConverter createExternalConverter(LogicalType 
type) {
+        LogicalTypeRoot root = type.getTypeRoot();
+
+        if (root == LogicalTypeRoot.ARRAY) {
+            return (val, index, statement) ->
+                    statement.setObject(index, 
toExternalSerializer(val.getArray(index), type));
+        } else if (root == LogicalTypeRoot.MAP) {
+            return (val, index, statement) ->
+                    statement.setObject(index, 
toExternalSerializer(val.getMap(index), type));
+        } else {
+            return super.createExternalConverter(type);
+        }
+    }
+
+    // adding support to MAP and ARRAY types
+    private static Object toExternalSerializer(Object value, LogicalType type) 
{
+        switch (type.getTypeRoot()) {
+            case BOOLEAN:
+                return value;
+            case TINYINT:
+                return value instanceof Number ? ((Number) value).byteValue() 
: value;
+            case SMALLINT:
+                return value instanceof Number ? ((Number) value).shortValue() 
: value;
+            case INTEGER:
+            case INTERVAL_YEAR_MONTH:
+                return value instanceof Number ? ((Number) value).intValue() : 
value;
+            case BIGINT:
+            case INTERVAL_DAY_TIME:
+                return value instanceof Number ? ((Number) value).longValue() 
: value;
+            case FLOAT:
+                return value instanceof Number ? ((Number) value).floatValue() 
: value;
+            case DOUBLE:
+                return value instanceof Number ? ((Number) 
value).doubleValue() : value;
+            case CHAR:
+            case VARCHAR:
+                return value.toString();

Review Comment:
   Done



##########
pom.xml:
##########
@@ -230,6 +238,24 @@ under the License.
                 <version>4.5.13</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.apache.httpcomponents.core5</groupId>
+                <artifactId>httpcore5</artifactId>
+                <version>5.3.4</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.httpcomponents.core5</groupId>
+                <artifactId>httpcore5-h2</artifactId>
+                <version>5.3.4</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.httpcomponents.client5</groupId>
+                <artifactId>httpclient5</artifactId>

Review Comment:
   Done



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to