You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/06/16 05:58:40 UTC

[GitHub] [iceberg] jun-he commented on a change in pull request #2697: [python] Adding Unknown and Void transforms

jun-he commented on a change in pull request #2697:
URL: https://github.com/apache/iceberg/pull/2697#discussion_r652371530



##########
File path: python/iceberg/api/transforms/unknown_transform.py
##########
@@ -0,0 +1,61 @@
+# 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.
+
+from typing import Union
+
+from iceberg.api.types import StringType, Type
+
+from .transform import Transform
+
+
+class UnknownTransform(Transform):
+
+    def __init__(self, source_type: Type, transform: str):
+        self.source_type = source_type
+        self.transform = transform

Review comment:
       Similar to Java implementation, `__str__` should return `transform`.
   

##########
File path: python/iceberg/api/transforms/unknown_transform.py
##########
@@ -0,0 +1,61 @@
+# 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.
+
+from typing import Union
+
+from iceberg.api.types import StringType, Type
+
+from .transform import Transform
+
+
+class UnknownTransform(Transform):
+
+    def __init__(self, source_type: Type, transform: str):
+        self.source_type = source_type
+        self.transform = transform
+
+    def apply(self, value):
+        raise AttributeError(f"Cannot apply unsupported transform: {self.transform}")
+
+    def can_transform(self, type_var) -> bool:
+        # assume the transform function can be applied for this type because unknown transform is only used when parsing
+        # a transform in an existing table. a different Iceberg version must have already validated it.
+        return self.source_type == type_var
+
+    def get_result_type(self, source_type):
+        # the actual result type is not known
+        return StringType.get()
+
+    def project(self, name, predicate):
+        return None
+
+    def project_strict(self, name, predicate):
+        return None
+
+    def to_human_string(self, value) -> str:
+        return self.transform

Review comment:
       This should return `value` in string format instead of `transform`.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org