You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/12/21 12:24:47 UTC

[GitHub] [flink-table-store] JingsongLi commented on a diff in pull request #441: [FLINK-30423] Introduce generated codes for CastExecutor

JingsongLi commented on code in PR #441:
URL: https://github.com/apache/flink-table-store/pull/441#discussion_r1054328340


##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/casting/CastExecutor.java:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.table.store.file.casting;
+
+import org.apache.flink.table.api.TableException;
+
+import javax.annotation.Nullable;
+
+/**
+ * Interface to model a function that performs the casting of a value from one type to another.
+ * Copied from flink.
+ *
+ * @param <IN> Input internal type
+ * @param <OUT> Output internal type
+ */
+public interface CastExecutor<IN, OUT> {
+    /**
+     * Cast the input value. The output is null only and only if the input is null. The method
+     * throws an exception if something goes wrong when casting.
+     *
+     * @param value Input value.
+     */
+    @Nullable
+    OUT cast(@Nullable IN value) throws TableException;

Review Comment:
   I think all types of cast are null to null. So here this method can be `cast(IN value)`?



##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/casting/AbstractToStringCastExecutor.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.table.store.file.casting;
+
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.data.binary.BinaryStringData;
+import org.apache.flink.table.data.binary.BinaryStringDataUtil;
+
+import javax.annotation.Nullable;
+
+/**
+ * Cast input to string base implementation.
+ *
+ * @param <IN> the input value type.
+ */
+public abstract class AbstractToStringCastExecutor<IN> implements CastExecutor<IN, StringData> {
+    protected final boolean targetCharType;
+    protected final int targetLength;
+
+    AbstractToStringCastExecutor(boolean targetCharType, int targetLength) {
+        this.targetCharType = targetCharType;
+        this.targetLength = targetLength;
+    }
+
+    @Nullable
+    @Override
+    public StringData cast(@Nullable IN value) throws TableException {
+        boolean inputIsNull = value == null;

Review Comment:
   if (is null) return null;
   You may have misunderstood the codegen in Flink.
   Please add tests too.



##########
flink-table-store-core/src/main/java/org/apache/flink/table/store/file/casting/AbstractToStringCastExecutor.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.table.store.file.casting;
+
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.data.binary.BinaryStringData;
+import org.apache.flink.table.data.binary.BinaryStringDataUtil;
+
+import javax.annotation.Nullable;
+
+/**
+ * Cast input to string base implementation.
+ *
+ * @param <IN> the input value type.
+ */
+public abstract class AbstractToStringCastExecutor<IN> implements CastExecutor<IN, StringData> {

Review Comment:
   We don't need to have so many small classes, we can do some aggregation.
   Maybe we can just have a `CastExecutors` class, it contains all executors.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org