You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/08/26 07:10:42 UTC

[GitHub] [beam] slawomir-andrian commented on a change in pull request #12509: [BEAM-9898][BEAM-9899] SnowflakeIO.Write for cross-language with python wrapper and integration test

slawomir-andrian commented on a change in pull request #12509:
URL: https://github.com/apache/beam/pull/12509#discussion_r477081860



##########
File path: sdks/python/apache_beam/io/external/xlang_snowflakeio_it_test.py
##########
@@ -0,0 +1,269 @@
+#
+# 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.
+#
+
+"""
+Integration test for cross-language snowflake io operations.
+
+Example run:
+
+python setup.py nosetests --tests=apache_beam.io.external.snowflake_test \
+--test-pipeline-options="
+  --server_name=<SNOWFLAKE_SERVER_NAME>
+  --username=<SNOWFLAKE_USERNAME>
+  --password=<SNOWFLAKE_PASSWORD>
+  --private_key_path=<PATH_TO_PRIVATE_KEY>
+  --private_key_passphrase=<PASSWORD_TO_PRIVATE_KEY>
+  --o_auth_token=<TOKEN>
+  --staging_bucket_name=<GCP_BUCKET_PATH>
+  --storage_integration_name=<SNOWFLAKE_STORAGE_INTEGRATION_NAME>
+  --database=<DATABASE>
+  --schema=<SCHEMA>
+  --role=<ROLE>
+  --warehouse=<WAREHOUSE>
+  --table=<TABLE_NAME>
+  --runner=FlinkRunner"
+"""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import argparse
+import binascii
+import logging
+import unittest
+from typing import ByteString
+from typing import NamedTuple
+
+import apache_beam as beam
+from apache_beam import coders
+from apache_beam.io.snowflake import CreateDisposition
+from apache_beam.io.snowflake import ReadFromSnowflake
+from apache_beam.io.snowflake import WriteDisposition
+from apache_beam.io.snowflake import WriteToSnowflake
+from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
+try:
+  from apache_beam.io.gcp.gcsfilesystem import GCSFileSystem
+except ImportError:
+  GCSFileSystem = None
+# pylint: enable=wrong-import-order, wrong-import-position, ungrouped-imports
+
+SCHEMA_STRING = """
+{"schema":[
+    {"dataType":{"type":"integer","precision":38,"scale":0},"name":"number_column","nullable":false},
+    {"dataType":{"type":"boolean"},"name":"boolean_column","nullable":false},
+    {"dataType":{"type":"binary","size":100},"name":"bytes_column","nullable":true}
+]}
+"""
+
+TestRow = NamedTuple(
+    'TestRow',
+    [
+        ('number_column', int),
+        ('boolean_column', bool),
+        ('bytes_column', ByteString),
+    ])
+
+coders.registry.register_coder(TestRow, coders.RowCoder)
+
+NUM_RECORDS = 100
+
+
+@unittest.skipIf(GCSFileSystem is None, 'GCP dependencies are not installed')
+@unittest.skipIf(
+    TestPipeline().get_option('server_name') is None,
+    'Snowflake IT test requires external configuration to be run.')
+class SnowflakeTest(unittest.TestCase):
+  def test_snowflake_write_read(self):
+    self.run_write()
+    self.run_read()
+
+  def run_write(self):
+    def user_data_mapper(test_row):
+      return [
+          str(test_row.number_column).encode('utf-8'),
+          str(test_row.boolean_column).encode('utf-8'),
+          binascii.hexlify(test_row.bytes_column),
+      ]
+
+    with TestPipeline(options=PipelineOptions(self.pipeline_args)) as p:
+      p.not_use_test_runner_api = True
+      _ = (
+          p
+          | 'Impulse' >> beam.Impulse()
+          | 'Generate' >> beam.FlatMap(lambda x: range(NUM_RECORDS))  # pylint: disable=range-builtin-not-iterating
+          | 'Map to TestRow' >> beam.Map(
+              lambda num: TestRow(
+                  num, num % 2 == 0, b"test" + str(num).encode()))
+          | WriteToSnowflake(

Review comment:
       @chamikaramj What are your thoughts?  Would you mind responding to @piotr-szuberski comment? Thanks!




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