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/09 07:35:13 UTC

[GitHub] [iceberg] jun-he opened a new pull request #2689: support custom target name in partition spec builder

jun-he opened a new pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689


   Support custom target name in partition spec builder and also fix some other issues. Additionally, add unit tests for partition spec.
   


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


[GitHub] [iceberg] jun-he commented on pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
jun-he commented on pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689#issuecomment-860295895


   Seems the failures are from linters
   ```
     linters run-test: commands[2] | mypy --ignore-missing-imports iceberg/
     iceberg/api/transforms/transform_util.py:20: error: Library stubs not installed for "pytz" (or incompatible with Python 3.8)
     iceberg/api/expressions/literals.py:23: error: Library stubs not installed for "pytz" (or incompatible with Python 3.8)
     iceberg/api/expressions/literals.py:23: note: Hint: "python3 -m pip install types-pytz"
     iceberg/api/expressions/literals.py:23: note: (or run "mypy --install-types" to install all missing stub packages)
     iceberg/api/expressions/literals.py:23: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
     iceberg/api/expressions/literals.py:385: error: Library stubs not installed for "dateutil.parser" (or incompatible with Python 3.8)
     iceberg/api/expressions/literals.py:385: note: Hint: "python3 -m pip install types-python-dateutil"
     iceberg/api/expressions/literals.py:385: error: Library stubs not installed for "dateutil" (or incompatible with Python 3.8)
   ```
   
   


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


[GitHub] [iceberg] TGooch44 commented on a change in pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
TGooch44 commented on a change in pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689#discussion_r649099139



##########
File path: python/iceberg/api/partition_spec.py
##########
@@ -213,106 +214,145 @@ def with_spec_id(self, spec_id):
         self.spec_id = spec_id
         return self
 
-    def check_and_add_partition_name(self, name):
+    def check_and_add_partition_name(self, name, source_column_id=None):
+        schema_field = self.schema.find_field(name)
+        if source_column_id is not None:
+            if schema_field is not None and schema_field.field_id != source_column_id:
+                raise ValueError("Cannot create identity partition sourced from different field in schema: %s" % name)
+        else:
+            if schema_field is not None:
+                raise ValueError("Cannot create partition from name that exists in schema: %s" % name)
+
         if name is None or name == "":
-            raise RuntimeError("Cannot use empty or null partition name")
+            raise ValueError("Cannot use empty or null partition name: %s" % name)
         if name in self.partition_names:
-            raise RuntimeError("Cannot use partition names more than once: %s" % name)
+            raise ValueError("Cannot use partition names more than once: %s" % name)
 
         self.partition_names.add(name)
         return self
 
+    def check_for_redundant_partitions(self, field):

Review comment:
       Do you think it's worthwhile introducing a function that checks for redundant partitions and adds the field?  Each transform method does the same block creating the partition field and then adding it.  Something like this:
   ```
   def check_redundant_and_add_field(self, field_id: int, name: str, transform: 'Transform') -> None:
           part_field = (PartitionField(field_id,
                                        self.__next_field_id(),
                                        name,
                                        transform))
           self.check_for_redundant_partitions(part_field)
           self.fields.append(part_field)
   ```

##########
File path: python/tests/api/test_partition_spec.py
##########
@@ -0,0 +1,84 @@
+# 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.
+import unittest
+
+from iceberg.api import PartitionSpec
+from iceberg.api.schema import Schema
+from iceberg.api.types import (BinaryType,
+                               DateType,
+                               DecimalType,
+                               FixedType,
+                               IntegerType,
+                               LongType,
+                               NestedField,
+                               StringType,
+                               TimestampType,
+                               TimeType,
+                               UUIDType)
+from tests.api.test_helpers import TestHelpers
+
+
+class TestConversions(unittest.TestCase):
+
+    def test_transforms(self):
+        schema = Schema(NestedField.required(1, "i", IntegerType.get()),
+                        NestedField.required(2, "l", LongType.get()),
+                        NestedField.required(3, "d", DateType.get()),
+                        NestedField.required(4, "t", TimeType.get()),
+                        NestedField.required(5, "ts", TimestampType.without_timezone()),
+                        NestedField.required(6, "dec", DecimalType.of(9, 2)),
+                        NestedField.required(7, "s", StringType.get()),
+                        NestedField.required(8, "u", UUIDType.get()),
+                        NestedField.required(9, "f", FixedType.of_length(3)),
+                        NestedField.required(10, "b", BinaryType.get()))
+        specs = [PartitionSpec.builder_for(schema).identity("i").build(),
+                 PartitionSpec.builder_for(schema).identity("l").build(),
+                 PartitionSpec.builder_for(schema).identity("d").build(),
+                 PartitionSpec.builder_for(schema).identity("t").build(),
+                 PartitionSpec.builder_for(schema).identity("ts").build(),
+                 PartitionSpec.builder_for(schema).identity("dec").build(),
+                 PartitionSpec.builder_for(schema).identity("s").build(),
+                 PartitionSpec.builder_for(schema).identity("u").build(),
+                 PartitionSpec.builder_for(schema).identity("f").build(),
+                 PartitionSpec.builder_for(schema).identity("b").build(),
+                 PartitionSpec.builder_for(schema).bucket("i", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("l", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("d", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("t", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("ts", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("dec", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("s", 128).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).bucket("u", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("f", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("b", 128).build(),
+                 PartitionSpec.builder_for(schema).year("d").build(),
+                 PartitionSpec.builder_for(schema).month("d").build(),
+                 PartitionSpec.builder_for(schema).day("d").build(),
+                 PartitionSpec.builder_for(schema).year("ts").build(),
+                 PartitionSpec.builder_for(schema).month("ts").build(),
+                 PartitionSpec.builder_for(schema).day("ts").build(),
+                 PartitionSpec.builder_for(schema).hour("ts").build(),
+                 PartitionSpec.builder_for(schema).truncate("i", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("l", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("dec", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("s", 10).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).add_without_field_id(6, "dec_unsupported", "unsupported").build(),

Review comment:
       Is this not supported?




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


[GitHub] [iceberg] jun-he commented on a change in pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
jun-he commented on a change in pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689#discussion_r650595821



##########
File path: python/iceberg/api/partition_spec.py
##########
@@ -213,106 +214,145 @@ def with_spec_id(self, spec_id):
         self.spec_id = spec_id
         return self
 
-    def check_and_add_partition_name(self, name):
+    def check_and_add_partition_name(self, name, source_column_id=None):
+        schema_field = self.schema.find_field(name)
+        if source_column_id is not None:
+            if schema_field is not None and schema_field.field_id != source_column_id:
+                raise ValueError("Cannot create identity partition sourced from different field in schema: %s" % name)
+        else:
+            if schema_field is not None:
+                raise ValueError("Cannot create partition from name that exists in schema: %s" % name)
+
         if name is None or name == "":
-            raise RuntimeError("Cannot use empty or null partition name")
+            raise ValueError("Cannot use empty or null partition name: %s" % name)
         if name in self.partition_names:
-            raise RuntimeError("Cannot use partition names more than once: %s" % name)
+            raise ValueError("Cannot use partition names more than once: %s" % name)
 
         self.partition_names.add(name)
         return self
 
+    def check_for_redundant_partitions(self, field):

Review comment:
       Yep, good idea. We can actually update `check_for_redundant_partitions` method to include adding field.
   

##########
File path: python/tests/api/test_partition_spec.py
##########
@@ -0,0 +1,84 @@
+# 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.
+import unittest
+
+from iceberg.api import PartitionSpec
+from iceberg.api.schema import Schema
+from iceberg.api.types import (BinaryType,
+                               DateType,
+                               DecimalType,
+                               FixedType,
+                               IntegerType,
+                               LongType,
+                               NestedField,
+                               StringType,
+                               TimestampType,
+                               TimeType,
+                               UUIDType)
+from tests.api.test_helpers import TestHelpers
+
+
+class TestConversions(unittest.TestCase):
+
+    def test_transforms(self):
+        schema = Schema(NestedField.required(1, "i", IntegerType.get()),
+                        NestedField.required(2, "l", LongType.get()),
+                        NestedField.required(3, "d", DateType.get()),
+                        NestedField.required(4, "t", TimeType.get()),
+                        NestedField.required(5, "ts", TimestampType.without_timezone()),
+                        NestedField.required(6, "dec", DecimalType.of(9, 2)),
+                        NestedField.required(7, "s", StringType.get()),
+                        NestedField.required(8, "u", UUIDType.get()),
+                        NestedField.required(9, "f", FixedType.of_length(3)),
+                        NestedField.required(10, "b", BinaryType.get()))
+        specs = [PartitionSpec.builder_for(schema).identity("i").build(),
+                 PartitionSpec.builder_for(schema).identity("l").build(),
+                 PartitionSpec.builder_for(schema).identity("d").build(),
+                 PartitionSpec.builder_for(schema).identity("t").build(),
+                 PartitionSpec.builder_for(schema).identity("ts").build(),
+                 PartitionSpec.builder_for(schema).identity("dec").build(),
+                 PartitionSpec.builder_for(schema).identity("s").build(),
+                 PartitionSpec.builder_for(schema).identity("u").build(),
+                 PartitionSpec.builder_for(schema).identity("f").build(),
+                 PartitionSpec.builder_for(schema).identity("b").build(),
+                 PartitionSpec.builder_for(schema).bucket("i", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("l", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("d", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("t", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("ts", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("dec", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("s", 128).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).bucket("u", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("f", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("b", 128).build(),
+                 PartitionSpec.builder_for(schema).year("d").build(),
+                 PartitionSpec.builder_for(schema).month("d").build(),
+                 PartitionSpec.builder_for(schema).day("d").build(),
+                 PartitionSpec.builder_for(schema).year("ts").build(),
+                 PartitionSpec.builder_for(schema).month("ts").build(),
+                 PartitionSpec.builder_for(schema).day("ts").build(),
+                 PartitionSpec.builder_for(schema).hour("ts").build(),
+                 PartitionSpec.builder_for(schema).truncate("i", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("l", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("dec", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("s", 10).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).add_without_field_id(6, "dec_unsupported", "unsupported").build(),

Review comment:
       Yep, put todos for unimplemented Transforms, e.g. `BucketUUID`, etc. Also, need to update `from_string` to support unrecognized cases. So I think it might be better to have them in a different PR.
   

##########
File path: python/tests/api/test_partition_spec.py
##########
@@ -0,0 +1,84 @@
+# 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.
+import unittest
+
+from iceberg.api import PartitionSpec
+from iceberg.api.schema import Schema
+from iceberg.api.types import (BinaryType,
+                               DateType,
+                               DecimalType,
+                               FixedType,
+                               IntegerType,
+                               LongType,
+                               NestedField,
+                               StringType,
+                               TimestampType,
+                               TimeType,
+                               UUIDType)
+from tests.api.test_helpers import TestHelpers
+
+
+class TestConversions(unittest.TestCase):
+
+    def test_transforms(self):
+        schema = Schema(NestedField.required(1, "i", IntegerType.get()),
+                        NestedField.required(2, "l", LongType.get()),
+                        NestedField.required(3, "d", DateType.get()),
+                        NestedField.required(4, "t", TimeType.get()),
+                        NestedField.required(5, "ts", TimestampType.without_timezone()),
+                        NestedField.required(6, "dec", DecimalType.of(9, 2)),
+                        NestedField.required(7, "s", StringType.get()),
+                        NestedField.required(8, "u", UUIDType.get()),
+                        NestedField.required(9, "f", FixedType.of_length(3)),
+                        NestedField.required(10, "b", BinaryType.get()))
+        specs = [PartitionSpec.builder_for(schema).identity("i").build(),
+                 PartitionSpec.builder_for(schema).identity("l").build(),
+                 PartitionSpec.builder_for(schema).identity("d").build(),
+                 PartitionSpec.builder_for(schema).identity("t").build(),
+                 PartitionSpec.builder_for(schema).identity("ts").build(),
+                 PartitionSpec.builder_for(schema).identity("dec").build(),
+                 PartitionSpec.builder_for(schema).identity("s").build(),
+                 PartitionSpec.builder_for(schema).identity("u").build(),
+                 PartitionSpec.builder_for(schema).identity("f").build(),
+                 PartitionSpec.builder_for(schema).identity("b").build(),
+                 PartitionSpec.builder_for(schema).bucket("i", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("l", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("d", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("t", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("ts", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("dec", 128).build(),
+                 PartitionSpec.builder_for(schema).bucket("s", 128).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).bucket("u", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("f", 128).build(),
+                 # PartitionSpec.builder_for(schema).bucket("b", 128).build(),
+                 PartitionSpec.builder_for(schema).year("d").build(),
+                 PartitionSpec.builder_for(schema).month("d").build(),
+                 PartitionSpec.builder_for(schema).day("d").build(),
+                 PartitionSpec.builder_for(schema).year("ts").build(),
+                 PartitionSpec.builder_for(schema).month("ts").build(),
+                 PartitionSpec.builder_for(schema).day("ts").build(),
+                 PartitionSpec.builder_for(schema).hour("ts").build(),
+                 PartitionSpec.builder_for(schema).truncate("i", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("l", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("dec", 10).build(),
+                 PartitionSpec.builder_for(schema).truncate("s", 10).build(),
+                 # todo support them
+                 # PartitionSpec.builder_for(schema).add_without_field_id(6, "dec_unsupported", "unsupported").build(),

Review comment:
       Yep, put todos for unimplemented Transforms, e.g. `BucketUUID`, etc. Also, need to update `from_string` to support unrecognized cases. In Java, it returns `return new UnknownTransform<>(type, transform); `
   So I think it might be better to have them in a different PR.
   




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


[GitHub] [iceberg] jun-he commented on pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
jun-he commented on pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689#issuecomment-858384924


   @TGooch44 Thanks for the comment. Please let me know other related changes and I can add them. Also, we may ship them separately with multiple PRs.


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


[GitHub] [iceberg] TGooch44 merged pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
TGooch44 merged pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689


   


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


[GitHub] [iceberg] TGooch44 commented on pull request #2689: [Python] support custom target name in partition spec builder

Posted by GitBox <gi...@apache.org>.
TGooch44 commented on pull request #2689:
URL: https://github.com/apache/iceberg/pull/2689#issuecomment-857650453


   Hi Jun, I think I have a very similar PR queued up on this.  Let me review what you have here, and see what else needs to be added(I can rebase me PR).  There is a lot of work in the partition spec that needs to be rolled out and I've been lagging on getting the PR's to the Open source


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