chamikaramj commented on a change in pull request #12149:
URL: https://github.com/apache/beam/pull/12149#discussion_r463341503



##########
File path: sdks/python/apache_beam/io/external/snowflake.py
##########
@@ -0,0 +1,185 @@
+#
+# 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.
+#
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import typing
+
+from past.builtins import unicode
+
+import apache_beam as beam
+from apache_beam.transforms.external import BeamJarExpansionService
+from apache_beam.transforms.external import ExternalTransform
+from apache_beam.transforms.external import NamedTupleBasedPayloadBuilder
+
+"""Snowflake transforms tested against Flink portable runner.
+  **Setup**
+  Transforms provided in this module are cross-language transforms
+  implemented in the Beam Java SDK. During the pipeline construction, Python 
SDK
+  will connect to a Java expansion service to expand these transforms.
+  To facilitate this, a small amount of setup is needed before using these
+  transforms in a Beam Python pipeline.
+  There are several ways to setup cross-language Snowflake transforms.
+  * Option 1: use the default expansion service
+  * Option 2: specify a custom expansion service
+  See below for details regarding each of these options.
+  *Option 1: Use the default expansion service*
+  This is the recommended and easiest setup option for using Python Kafka
+  transforms. This option is only available for Beam 2.22.0 and later.

Review comment:
       Pls drop "This option is only available for Beam 2.22.0 and later". This 
was just for Kafka.

##########
File path: sdks/python/apache_beam/io/external/snowflake.py
##########
@@ -0,0 +1,144 @@
+#
+# 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.
+#
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import typing
+
+from past.builtins import unicode
+
+import apache_beam as beam
+from apache_beam.transforms.external import BeamJarExpansionService
+from apache_beam.transforms.external import ExternalTransform
+from apache_beam.transforms.external import NamedTupleBasedPayloadBuilder
+
+__all__ = ['ReadFromSnowflake']
+
+
+def default_io_expansion_service():
+  return BeamJarExpansionService('sdks:java:io:expansion-service:shadowJar')
+
+
+ReadFromSnowflakeSchema = typing.NamedTuple(
+    'WriteToSnowflakeSchema',
+    [
+        ('server_name', unicode),
+        ('schema', unicode),
+        ('database', unicode),
+        ('staging_bucket_name', unicode),
+        ('storage_integration_name', unicode),
+        ('username', typing.Optional[unicode]),
+        ('password', typing.Optional[unicode]),
+        ('private_key_path', typing.Optional[unicode]),
+        ('private_key_passphrase', typing.Optional[unicode]),
+        ('o_auth_token', typing.Optional[unicode]),
+        ('table', typing.Optional[unicode]),
+        ('query', typing.Optional[unicode]),
+    ])
+
+
+class ReadFromSnowflake(beam.PTransform):
+  """An external PTransform which reads from Snowflake."""
+
+  URN = 'beam:external:java:snowflake:read:v1'
+
+  def __init__(
+      self,
+      server_name,
+      schema,
+      database,
+      staging_bucket_name,
+      storage_integration_name,
+      csv_mapper,
+      username=None,
+      password=None,
+      private_key_path=None,
+      private_key_passphrase=None,
+      o_auth_token=None,
+      table=None,
+      query=None,
+      expansion_service=None):
+    """
+    Initializes a read operation from Snowflake.
+
+    Required parameters:
+    :param server_name: full Snowflake server name with the following format
+        account.region.gcp.snowflakecomputing.com.
+    :param schema: name of the Snowflake schema in the database to use.
+    :param database: name of the Snowflake database to use.
+    :param staging_bucket_name: name of the Google Cloud Storage bucket.
+        Bucket will be used as a temporary location for storing CSV files.
+        Those temporary directories will be named
+        `sf_copy_csv_DATE_TIME_RANDOMSUFFIX`
+        and they will be removed automatically once Read operation finishes.
+    :param storage_integration_name: is the name of storage integration
+        object created according to Snowflake documentation.
+    :param csv_mapper: specifies a function which must translate
+        user-defined object to array of strings.
+        SnowflakeIO uses a COPY INTO <location> statement to
+        move data from a Snowflake table to Google Cloud Storage as CSV files.
+        These files are then downloaded via FileIO and processed line by line.
+        Each line is split into an array of Strings using the OpenCSV
+        The csv_mapper function job is to give the user the possibility to
+        convert the array of Strings to a user-defined type,
+        ie. GenericRecord for Avro or Parquet files, or custom objects.
+            Example:
+                ```
+                    def csv_mapper(strings_array):
+                               return User(strings_array[0], 
int(strings_array[1])))
+                ```
+    :param table or query: specifies a Snowflake table name or custom SQL query
+    :param expansion_service: specifies URL of expansion service.
+
+    Authentication parameters:
+    It's required to pass one of the following combinations of valid 
parameters:
+    :param username and password: specifies username and password
+        for username/password authentication method.
+    :param private_key_path and private_key_passphrase:
+        specifies a private key file and password
+        for key/ pair authentication method.
+    :param o_auth_token: specifies access token for OAuth authentication 
method.
+    """
+
+    self.params = ReadFromSnowflakeSchema(

Review comment:
       I added instructions for running Kafka against Dataflow for HEAD to 
here: 
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/kafkataxi/README.md
   
   For example, you need to setup "--experiments=use_runner_v2" and 
"--sdk_harness_container_image_overrides". Feel free to try this out and update 
the pydoc above if successful.




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


Reply via email to