Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello example update #1496

Closed

Conversation

maheshgurav
Copy link

No description provided.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label May 21, 2018
@sduskis
Copy link

sduskis commented May 22, 2018

@jabubake: This needs a review from your team. I'll also do first pass to make sure that this is right.

@maheshgurav
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels May 24, 2018
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('project_id', help='Your Cloud Platform project ID.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Cloud Platform/Google Cloud Platform/

# 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.
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert an empty line after license

- Create a Cloud Bigtable cluster.
https://cloud.google.com/bigtable/docs/creating-cluster
- Set your Google Application Default Credentials.
https://developers.google.com/identity/protocols/application-default-credentials
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def main(project_id, instance_id, table_id):
# [START connecting_to_bigtable]
# The client must be created with admin=True because it will create a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update comment to # Set admin=True to create an client that can perform admin tasks like creating a table.

# [START creating_a_table]
print('Creating the {} table.'.format(table_id))
table = instance.table(table_id)
table.create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle error if any on table creation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain, only exception handling needs to add or we should add checks like whether a table already exists etc.?


# [START scanning rows with filter]
print('Scanning for all greetings:')
rows = table.yield_rows(filter_=CellsRowLimitFilter(1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment / logging statement to what this filter means would be useful.

formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('project_id', help='Your Cloud Platform project ID.')
parser.add_argument(
'instance_id', help='ID of the Cloud Bigtable instance to connect to.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your Cloud Bigtable instance ID

'instance_id', help='ID of the Cloud Bigtable instance to connect to.')
parser.add_argument(
'--table',
help='Table to create and destroy.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/destroy/delete/g

# [END deleting_a_table]


if __name__ == '__main1__':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/main1/main/

RowSampleFilter, ColumnRangeFilter, SinkFilter, RowKeyRegexFilter,\
TimestampRange, ApplyLabelFilter, ColumnQualifierRegexFilter,\
CellsRowLimitFilter, CellsColumnLimitFilter, _BoolFilter, ValueRangeFilter
from datetime import datetime, timezone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran into issue w/ timezone included on MacOS X. Samples are expected to be compatible with Python 2.7 and 3.4+. I see similar issues on Github that this may not work with 2.7 ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, issues with Python 2.7.
What I observed was, we need to use datetime.datetime object and the object needs to pass is compatible with Python 3. For now, we removed timestamp thing from code as per comment from Solomon. But this needs to address this issue in Bigtable code if we want to run with Python 2.7.

'Hello Python!',
]

local_timezone = datetime.now(timezone.utc).astimezone().tzinfo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this. This does not seem to be used anywhere.

row.set_cell(
column_family_id,
column_id,
value.encode('utf-8'), timestamp=datetime.now(tz=pytz.timezone('UTC')))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, please remove the timestamp. We'll address this later.

- Fixed print statement

- Added filter while using read_row function
Added exception handling block while creating table

Added method to check whether table already exists

Added table already exists check before creating table
# [END deleting_a_table]


def check_table_already_exists(table_id, instance):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a table.exists() method? If so, please use that instead. If not, then we need to file a feature request in https://github.com/GoogleCloudPlatform/google-cloud-python for that method.

@AVaksman
Copy link
Contributor

AVaksman commented Sep 3, 2018

@sduskis I believe this PR could be closed. Hello World example was updated with #1670

@engelke
Copy link
Collaborator

engelke commented Nov 19, 2018

Thank you for your submission. Unfortunately, it has been outdated by other code updates since submission, so we are closing it. I hope you continue to contribute to this or other projects.

@engelke engelke closed this Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants