[ 
https://issues.apache.org/jira/browse/BEAM-3342?focusedWorklogId=186076&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-186076
 ]

ASF GitHub Bot logged work on BEAM-3342:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Jan/19 00:26
            Start Date: 17/Jan/19 00:26
    Worklog Time Spent: 10m 
      Work Description: chamikaramj commented on pull request #7367: 
[BEAM-3342] Create a Cloud Bigtable Python connector Write
URL: https://github.com/apache/beam/pull/7367#discussion_r248501682
 
 

 ##########
 File path: sdks/python/apache_beam/io/gcp/bigtable_io_test.py
 ##########
 @@ -0,0 +1,190 @@
+#
+# 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.
+#
+
+"""Unittest for GCP Bigtable testing."""
+from __future__ import absolute_import
+
+import datetime
+import logging
+import random
+import string
+import unittest
+import uuid
+
+import pytz
+
+import apache_beam as beam
+from apache_beam.io.gcp.bigtable_io import BigtableConfiguration
+from apache_beam.io.gcp.bigtable_io import WriteToBigtable
+from apache_beam.metrics.metric import MetricsFilter
+from apache_beam.options.pipeline_options import PipelineOptions
+from apache_beam.runners.runner import PipelineState
+from apache_beam.testing.test_pipeline import TestPipeline
+
+# Protect against environments where bigtable library is not available.
+# pylint: disable=wrong-import-order, wrong-import-position
+try:
+  from google.cloud._helpers import _datetime_from_microseconds
+  from google.cloud._helpers import _microseconds_from_datetime
+  from google.cloud._helpers import UTC
+  from google.cloud.bigtable import row, column_family, Client
+except ImportError:
+  Client = None
+  UTC = pytz.utc
+  _microseconds_from_datetime = lambda label_stamp: label_stamp
+  _datetime_from_microseconds = lambda micro: micro
+
+
+EXISTING_INSTANCES = []
+LABEL_KEY = u'python-bigtable-beam'
+label_stamp = datetime.datetime.utcnow().replace(tzinfo=UTC)
+label_stamp_micros = _microseconds_from_datetime(label_stamp)
+LABELS = {LABEL_KEY: str(label_stamp_micros)}
+
+
+def _retry_on_unavailable(exc):
+  """Retry only errors whose status code is 'UNAVAILABLE'."""
+  from grpc import StatusCode
+  return exc.code() == StatusCode.UNAVAILABLE
+
+
+class GenerateDirectRows(beam.PTransform):
+  """ Generates an iterator of DirectRow object to process on beam pipeline.
+
+  """
+  def __init__(self, number, **kwargs):
+    super(GenerateDirectRows, self).__init__(**kwargs)
+    self.number = number
+    self.rand = random.choice(string.ascii_letters + string.digits)
+    self.column_family_id = 'cf1'
+
+  def _generate(self):
+    value = ''.join(self.rand for i in range(100))
+
+    for index in range(self.number):
+      key = "beam_key%s" % ('{0:07}'.format(index))
+      direct_row = row.DirectRow(row_key=key)
+      for column_id in range(10):
+        direct_row.set_cell(self.column_family_id,
+                            ('field%s' % column_id).encode('utf-8'),
+                            value,
+                            datetime.datetime.now())
+      yield direct_row
+
+  def expand(self, pvalue):
+    return (pvalue
+            | beam.Create(self._generate()))
+
+
+@unittest.skipIf(Client is None, 'GCP Bigtable dependencies are not installed')
+class BigtableIOWriteIT(unittest.TestCase):
 
 Review comment:
   Probably better to move the integration test to a separate module. For 
example, 
https://github.com/apache/beam/blob/master/sdks/python/apache_beam/examples/cookbook/bigquery_tornadoes_it_test.py
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 186076)
    Time Spent: 8h 20m  (was: 8h 10m)

> Create a Cloud Bigtable Python connector
> ----------------------------------------
>
>                 Key: BEAM-3342
>                 URL: https://issues.apache.org/jira/browse/BEAM-3342
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-py-core
>            Reporter: Solomon Duskis
>            Assignee: Solomon Duskis
>            Priority: Major
>          Time Spent: 8h 20m
>  Remaining Estimate: 0h
>
> I would like to create a Cloud Bigtable python connector.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to