Skip to content

Commit

Permalink
Merge pull request #47 from ydb-platform/improve-example
Browse files Browse the repository at this point in the history
improve example: avoid os.path.join
  • Loading branch information
gridnevvvit authored Aug 23, 2022
2 parents 16d979c + 0c1f45a commit f1bdd74
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions examples/basic_example_v1/basic_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import os

import posixpath
import ydb
import basic_example_data

Expand Down Expand Up @@ -258,7 +257,7 @@ def callee(session):

def describe_table(pool, path, name):
def callee(session):
result = session.describe_table(os.path.join(path, name))
result = session.describe_table(posixpath.join(path, name))
print("\n> describe table: series")
for column in result.columns:
print("column, name:", column.name, ",", str(column.type.item).strip())
Expand All @@ -277,7 +276,7 @@ def bulk_upsert(table_client, path):
.add_column("air_date", ydb.OptionalType(ydb.PrimitiveType.Uint64))
)
rows = basic_example_data.get_episodes_data_for_bulk_upsert()
table_client.bulk_upsert(os.path.join(path, "episodes"), rows, column_types)
table_client.bulk_upsert(posixpath.join(path, "episodes"), rows, column_types)


def is_directory_exists(driver, path):
Expand All @@ -291,11 +290,11 @@ def ensure_path_exists(driver, database, path):
paths_to_create = list()
path = path.rstrip("/")
while path not in ("", database):
full_path = os.path.join(database, path)
full_path = posixpath.join(database, path)
if is_directory_exists(driver, full_path):
break
paths_to_create.append(full_path)
path = os.path.dirname(path).rstrip("/")
path = posixpath.dirname(path).rstrip("/")

while len(paths_to_create) > 0:
full_path = paths_to_create.pop(-1)
Expand All @@ -310,7 +309,7 @@ def run(endpoint, database, path):

ensure_path_exists(driver, database, path)

full_path = os.path.join(database, path)
full_path = posixpath.join(database, path)

create_tables(pool, full_path)

Expand Down

0 comments on commit f1bdd74

Please sign in to comment.