o-nikolas commented on code in PR #65816:
URL: https://github.com/apache/airflow/pull/65816#discussion_r3139647393


##########
providers/amazon/src/airflow/providers/amazon/aws/hooks/s3tables.py:
##########
@@ -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.
+"""Interact with Amazon S3 Tables."""
+
+from __future__ import annotations
+
+from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
+
+
+class S3TablesHook(AwsBaseHook):
+    """
+    Interact with the Amazon S3 Tables API.
+
+    Provide thin wrapper around 
:external+boto3:py:class:`boto3.client("s3tables") <S3Tables.Client>`.
+
+    Additional arguments (such as ``aws_conn_id``) may be specified and
+    are passed down to the underlying AwsBaseHook.
+
+    .. seealso::
+        - :class:`airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
+    """
+
+    client_type = "s3tables"
+
+    def __init__(self, *args, **kwargs) -> None:
+        kwargs["client_type"] = self.client_type
+        super().__init__(*args, **kwargs)
+
+    def create_table(
+        self,
+        table_bucket_arn: str,
+        namespace: str,
+        name: str,
+        fmt: str = "ICEBERG",

Review Comment:
   Try to avoid C/C++ style variable names, in favour of more Pythonic/PEP8 
names, here I'd prefer `format`. Same for the operator. 



##########
providers/amazon/tests/system/amazon/aws/example_s3tables.py:
##########
@@ -0,0 +1,147 @@
+# 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 __future__ import annotations
+
+from datetime import datetime
+
+from airflow.decorators import task
+from airflow.providers.amazon.aws.operators.s3tables import 
S3TablesCreateTableOperator
+from airflow.providers.common.compat.sdk import DAG, chain
+
+try:
+    from airflow.sdk import TriggerRule
+except ImportError:
+    from airflow.utils.trigger_rule import TriggerRule
+
+from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder
+
+DAG_ID = "example_s3tables"
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+SCHEMA = {
+    "iceberg": {
+        "schema": {
+            "fields": [
+                {"name": "id", "type": "int", "required": True},
+                {"name": "name", "type": "string", "required": False},
+            ]
+        }
+    }
+}
+
+with DAG(
+    dag_id=DAG_ID,
+    schedule="@once",
+    start_date=datetime(2021, 1, 1),
+    catchup=False,
+    tags=["example"],
+) as dag:
+    test_context = sys_test_context_task()
+    env_id = test_context[ENV_ID_KEY]
+
+    bucket_name = f"{env_id}-s3tables"
+    namespace = f"{env_id}ns"
+    table_name = f"{env_id}tbl"
+
+    @task
+    def create_table_bucket(name: str) -> str:
+        """Create an S3 Tables bucket and return its ARN."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        resp = client.create_table_bucket(name=name)
+        return resp["arn"]
+
+    @task
+    def create_namespace(table_bucket_arn: str, ns: str):
+        """Create a namespace in the table bucket."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        client.create_namespace(tableBucketARN=table_bucket_arn, 
namespace=[ns])
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_table(table_bucket_arn: str, ns: str, name: str):
+        """Delete the table."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_table(tableBucketARN=table_bucket_arn, namespace=ns, 
name=name)
+        except client.exceptions.NotFoundException:
+            pass
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_namespace(table_bucket_arn: str, ns: str):
+        """Delete the namespace."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_namespace(tableBucketARN=table_bucket_arn, 
namespace=ns)
+        except client.exceptions.NotFoundException:
+            pass
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_table_bucket(table_bucket_arn: str):
+        """Delete the table bucket."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_table_bucket(tableBucketARN=table_bucket_arn)
+        except client.exceptions.NotFoundException:
+            pass
+
+    bucket_arn = create_table_bucket(name=bucket_name)
+    setup_ns = create_namespace(table_bucket_arn=bucket_arn, ns=namespace)
+
+    # [START howto_operator_s3tables_create_table]
+    create_table = S3TablesCreateTableOperator(
+        task_id="create_table",
+        table_bucket_arn=bucket_arn,
+        namespace=namespace,
+        table_name=table_name,
+        metadata=SCHEMA,
+    )
+    # [END howto_operator_s3tables_create_table]
+
+    cleanup_table = delete_table(table_bucket_arn=bucket_arn, ns=namespace, 
name=table_name)
+    cleanup_ns = delete_namespace(table_bucket_arn=bucket_arn, ns=namespace)
+    cleanup_bucket = delete_table_bucket(table_bucket_arn=bucket_arn)

Review Comment:
   These can all directly go into the `chain(...)` call. No need to declare the 
single use variables for these one-liners.



##########
providers/amazon/tests/system/amazon/aws/example_s3tables.py:
##########
@@ -0,0 +1,147 @@
+# 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 __future__ import annotations
+
+from datetime import datetime
+
+from airflow.decorators import task
+from airflow.providers.amazon.aws.operators.s3tables import 
S3TablesCreateTableOperator
+from airflow.providers.common.compat.sdk import DAG, chain
+
+try:
+    from airflow.sdk import TriggerRule
+except ImportError:
+    from airflow.utils.trigger_rule import TriggerRule
+
+from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder
+
+DAG_ID = "example_s3tables"
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+SCHEMA = {
+    "iceberg": {
+        "schema": {
+            "fields": [
+                {"name": "id", "type": "int", "required": True},
+                {"name": "name", "type": "string", "required": False},
+            ]
+        }
+    }
+}
+
+with DAG(
+    dag_id=DAG_ID,
+    schedule="@once",
+    start_date=datetime(2021, 1, 1),
+    catchup=False,
+    tags=["example"],
+) as dag:
+    test_context = sys_test_context_task()
+    env_id = test_context[ENV_ID_KEY]
+
+    bucket_name = f"{env_id}-s3tables"
+    namespace = f"{env_id}ns"
+    table_name = f"{env_id}tbl"
+
+    @task
+    def create_table_bucket(name: str) -> str:
+        """Create an S3 Tables bucket and return its ARN."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        resp = client.create_table_bucket(name=name)
+        return resp["arn"]
+
+    @task
+    def create_namespace(table_bucket_arn: str, ns: str):
+        """Create a namespace in the table bucket."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        client.create_namespace(tableBucketARN=table_bucket_arn, 
namespace=[ns])
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_table(table_bucket_arn: str, ns: str, name: str):
+        """Delete the table."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_table(tableBucketARN=table_bucket_arn, namespace=ns, 
name=name)
+        except client.exceptions.NotFoundException:
+            pass
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_namespace(table_bucket_arn: str, ns: str):
+        """Delete the namespace."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_namespace(tableBucketARN=table_bucket_arn, 
namespace=ns)
+        except client.exceptions.NotFoundException:
+            pass
+
+    @task(trigger_rule=TriggerRule.ALL_DONE)
+    def delete_table_bucket(table_bucket_arn: str):
+        """Delete the table bucket."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        try:
+            client.delete_table_bucket(tableBucketARN=table_bucket_arn)
+        except client.exceptions.NotFoundException:
+            pass
+
+    bucket_arn = create_table_bucket(name=bucket_name)
+    setup_ns = create_namespace(table_bucket_arn=bucket_arn, ns=namespace)

Review Comment:
   ```suggestion
       setup_namespace = create_namespace(table_bucket_arn=bucket_arn, 
ns=namespace)
   ```
   and its uses elsewhere (same for `cleanup_ns`)



##########
providers/amazon/tests/system/amazon/aws/example_s3tables.py:
##########
@@ -0,0 +1,147 @@
+# 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 __future__ import annotations
+
+from datetime import datetime
+
+from airflow.decorators import task
+from airflow.providers.amazon.aws.operators.s3tables import 
S3TablesCreateTableOperator
+from airflow.providers.common.compat.sdk import DAG, chain
+
+try:
+    from airflow.sdk import TriggerRule
+except ImportError:
+    from airflow.utils.trigger_rule import TriggerRule
+
+from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder
+
+DAG_ID = "example_s3tables"
+
+sys_test_context_task = SystemTestContextBuilder().build()
+
+SCHEMA = {
+    "iceberg": {
+        "schema": {
+            "fields": [
+                {"name": "id", "type": "int", "required": True},
+                {"name": "name", "type": "string", "required": False},
+            ]
+        }
+    }
+}
+
+with DAG(
+    dag_id=DAG_ID,
+    schedule="@once",
+    start_date=datetime(2021, 1, 1),
+    catchup=False,
+    tags=["example"],
+) as dag:
+    test_context = sys_test_context_task()
+    env_id = test_context[ENV_ID_KEY]
+
+    bucket_name = f"{env_id}-s3tables"
+    namespace = f"{env_id}ns"
+    table_name = f"{env_id}tbl"
+
+    @task
+    def create_table_bucket(name: str) -> str:
+        """Create an S3 Tables bucket and return its ARN."""
+        import boto3
+
+        client = boto3.client("s3tables")
+        resp = client.create_table_bucket(name=name)
+        return resp["arn"]
+
+    @task
+    def create_namespace(table_bucket_arn: str, ns: str):

Review Comment:
   ```suggestion
       def create_namespace(table_bucket_arn: str, namespace: str):
   ```
   
   Same with the other methods 



##########
providers/amazon/src/airflow/providers/amazon/aws/operators/s3tables.py:
##########
@@ -0,0 +1,98 @@
+#
+# 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.
+"""Amazon S3 Tables operators."""
+
+from __future__ import annotations
+
+from collections.abc import Sequence
+from typing import TYPE_CHECKING, Any
+
+from airflow.providers.amazon.aws.hooks.s3tables import S3TablesHook
+from airflow.providers.amazon.aws.operators.base_aws import AwsBaseOperator
+from airflow.providers.amazon.aws.utils.mixins import aws_template_fields
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class S3TablesCreateTableOperator(AwsBaseOperator[S3TablesHook]):
+    """
+    Create a new table in an Amazon S3 Tables namespace.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:S3TablesCreateTableOperator`
+
+    :param table_bucket_arn: The ARN of the table bucket to create the table 
in. (templated)
+    :param namespace: The namespace to associate with the table. (templated)
+    :param table_name: The name of the table. (templated)
+    :param fmt: The table format. Currently only ``ICEBERG`` is supported.
+    :param metadata: Optional Iceberg schema metadata. (templated)
+        Example: ``{"iceberg": {"schema": {"fields": [{"name": "id", "type": 
"int", "required": True}]}}}``
+    :param aws_conn_id: The Airflow connection used for AWS credentials.
+        If this is ``None`` or empty then the default boto3 behaviour is used. 
If
+        running Airflow in a distributed manner and aws_conn_id is None or
+        empty, then default boto3 configuration would be used (and must be
+        maintained on each worker node).
+    :param region_name: AWS region_name. If not specified then the default 
boto3 behaviour is used.
+    :param verify: Whether or not to verify SSL certificates. See:
+        
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html
+    :param botocore_config: Configuration dictionary (key-values) for botocore 
client. See:
+        
https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html
+    """
+
+    template_fields: Sequence[str] = aws_template_fields(
+        "table_bucket_arn", "namespace", "table_name", "metadata"

Review Comment:
   Any reason format was excluded from the templated fields?



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