[ https://issues.apache.org/jira/browse/BEAM-3342?focusedWorklogId=295111&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-295111 ]
ASF GitHub Bot logged work on BEAM-3342: ---------------------------------------- Author: ASF GitHub Bot Created on: 15/Aug/19 00:56 Start Date: 15/Aug/19 00:56 Worklog Time Spent: 10m Work Description: pabloem commented on pull request #8457: [BEAM-3342] Create a Cloud Bigtable IO connector for Python URL: https://github.com/apache/beam/pull/8457#discussion_r314140821 ########## File path: sdks/python/apache_beam/io/gcp/bigtableio_it_test.py ########## @@ -0,0 +1,189 @@ +# +# 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 GCP Bigtable testing.""" +from __future__ import absolute_import + +import argparse +import datetime +import logging +import random +import string +import time +import unittest +from nose.plugins.attrib import attr + +import apache_beam as beam +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.util import assert_that, equal_to +from apache_beam.transforms.combiners import Count + +try: + from google.cloud.bigtable import enums, row, column_family, Client +except ImportError: + Client = None + +import bigtableio + +class GenerateTestRows(beam.PTransform): + """ A PTransform to generate dummy rows to write to a Bigtable Table. + + A PTransform that generates a list of `DirectRow` and writes it to a Bigtable Table. + """ + def __init__(self): + super(self.__class__, self).__init__() + self.beam_options = {'project_id': PROJECT_ID, + 'instance_id': INSTANCE_ID, + 'table_id': TABLE_ID} + + def _generate(self): + for i in range(ROW_COUNT): + key = "key_%s" % ('{0:012}'.format(i)) + test_row = row.DirectRow(row_key=key) + value = ''.join(random.choice(LETTERS_AND_DIGITS) for _ in range(CELL_SIZE)) + for j in range(COLUMN_COUNT): + test_row.set_cell(column_family_id=COLUMN_FAMILY_ID, + column=('field%s' % j).encode('utf-8'), + value=value, + timestamp=datetime.datetime.now()) + yield test_row + + def expand(self, pvalue): + return (pvalue + | beam.Create(self._generate()) + | bigtableio.WriteToBigTable(project_id=self.beam_options['project_id'], + instance_id=self.beam_options['instance_id'], + table_id=self.beam_options['table_id'])) + +@unittest.skipIf(Client is None, 'GCP Bigtable dependencies are not installed') +class BigtableIOTest(unittest.TestCase): + """ Bigtable IO Connector Test + + This tests the connector both ways, first writing rows to a new table, then reading them and comparing the counters + """ + def setUp(self): + self.result = None + self.table = Client(project=PROJECT_ID, admin=True)\ + .instance(instance_id=INSTANCE_ID)\ + .table(TABLE_ID) + + if not self.table.exists(): + column_families = {COLUMN_FAMILY_ID: column_family.MaxVersionsGCRule(2)} + self.table.create(column_families=column_families) + logging.info('Table {} has been created!'.format(TABLE_ID)) + + @attr('IT') + def test_bigtable_io(self): + print 'Project ID: ', PROJECT_ID + print 'Instance ID:', INSTANCE_ID + print 'Table ID: ', TABLE_ID Review comment: Maybe avoid printing here, or use `logging.info` instead. If you do want to use print, use `print(...)` as a function (this is necessary for Py3 compatibility). ---------------------------------------------------------------- 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 Issue Time Tracking ------------------- Worklog Id: (was: 295111) Time Spent: 35h 50m (was: 35h 40m) > Create a Cloud Bigtable IO connector for Python > ----------------------------------------------- > > 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: 35h 50m > Remaining Estimate: 0h > > I would like to create a Cloud Bigtable python connector. -- This message was sent by Atlassian JIRA (v7.6.14#76016)