Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/aio/session_pool_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ydb.aio
import os


queries = [ # Tables description to create
"""
CREATE table `series` (
Expand Down
1 change: 0 additions & 1 deletion examples/basic_example_v1/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import basic_example
import logging


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
44 changes: 11 additions & 33 deletions examples/basic_example_v1/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def callee(session):
$format(DateTime::FromSeconds(CAST(DateTime::ToSeconds(DateTime::IntervalFromDays(CAST(release_date AS Int16))) AS Uint32))) AS release_date
FROM series
WHERE series_id = 1;
""".format(
path
),
""".format(path),
commit_tx=True,
)
print("\n> select_simple_transaction:")
Expand All @@ -124,9 +122,7 @@ def callee(session):
PRAGMA TablePathPrefix("{}");
UPSERT INTO episodes (series_id, season_id, episode_id, title) VALUES
(2, 6, 1, "TBD");
""".format(
path
),
""".format(path),
commit_tx=True,
)

Expand All @@ -148,9 +144,7 @@ def callee(session):
$format(DateTime::FromSeconds(CAST(DateTime::ToSeconds(DateTime::IntervalFromDays(CAST(air_date AS Int16))) AS Uint32))) AS air_date
FROM episodes
WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
""".format(
path
)
""".format(path)

data_query = ydb.types.DataQuery(
query,
Expand Down Expand Up @@ -196,9 +190,7 @@ def callee(session):
$format(DateTime::FromSeconds(CAST(DateTime::ToSeconds(DateTime::IntervalFromDays(CAST(air_date AS Int16))) AS Uint32))) AS air_date
FROM episodes
WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
""".format(
path
)
""".format(path)

prepared_query = session.prepare(query)
result_sets = session.transaction(ydb.SerializableReadWrite()).execute(
Expand Down Expand Up @@ -235,9 +227,7 @@ def callee(session):
UPDATE episodes
SET air_date = CAST(CurrentUtcDate() AS Uint64)
WHERE series_id = $seriesId AND season_id = $seasonId AND episode_id = $episodeId;
""".format(
path
)
""".format(path)
prepared_query = session.prepare(query)

# Get newly created transaction id
Expand All @@ -261,8 +251,7 @@ def callee(session):
def create_tables(pool, path):
def callee(session):
# Creating Series table
session.execute_scheme(
"""
session.execute_scheme("""
PRAGMA TablePathPrefix("{}");
CREATE table `series` (
`series_id` Uint64,
Expand All @@ -271,14 +260,10 @@ def callee(session):
`release_date` Uint64,
PRIMARY KEY (`series_id`)
)
""".format(
path
)
)
""".format(path))

# Creating Seasons table
session.execute_scheme(
"""
session.execute_scheme("""
PRAGMA TablePathPrefix("{}");
CREATE table `seasons` (
`series_id` Uint64,
Expand All @@ -288,14 +273,10 @@ def callee(session):
`last_aired` Uint64,
PRIMARY KEY (`series_id`, `season_id`)
)
""".format(
path
)
)
""".format(path))

# Creating Episodes table
session.execute_scheme(
"""
session.execute_scheme("""
PRAGMA TablePathPrefix("{}");
CREATE table `episodes` (
`series_id` Uint64,
Expand All @@ -305,10 +286,7 @@ def callee(session):
`air_date` Uint64,
PRIMARY KEY (`series_id`, `season_id`, `episode_id`)
)
""".format(
path
)
)
""".format(path))

return pool.retry_operation_sync(callee)

Expand Down
1 change: 0 additions & 1 deletion examples/basic_example_v2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from basic_example_async import run as run_async
import logging


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
25 changes: 8 additions & 17 deletions examples/basic_example_v2/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ydb
import basic_example_data


DropTablesQuery = """
DROP TABLE IF EXISTS series;
DROP TABLE IF EXISTS seasons;
Expand Down Expand Up @@ -100,11 +99,9 @@ def select_simple(pool: ydb.QuerySessionPool):
def upsert_simple(pool: ydb.QuerySessionPool):
print("\nPerforming UPSERT into episodes...")

pool.execute_with_retries(
"""
pool.execute_with_retries("""
UPSERT INTO episodes (series_id, season_id, episode_id, title) VALUES (2, 6, 1, "TBD");
"""
)
""")


def select_with_parameters(pool: ydb.QuerySessionPool, series_id, season_id, episode_id):
Expand Down Expand Up @@ -197,21 +194,18 @@ def drop_tables(pool: ydb.QuerySessionPool):

def create_tables(pool: ydb.QuerySessionPool):
print("\nCreating table series...")
pool.execute_with_retries(
"""
pool.execute_with_retries("""
CREATE table `series` (
`series_id` Int64,
`title` Utf8,
`series_info` Utf8,
`release_date` Date,
PRIMARY KEY (`series_id`)
)
"""
)
""")

print("\nCreating table seasons...")
pool.execute_with_retries(
"""
pool.execute_with_retries("""
CREATE table `seasons` (
`series_id` Int64,
`season_id` Int64,
Expand All @@ -220,12 +214,10 @@ def create_tables(pool: ydb.QuerySessionPool):
`last_aired` Date,
PRIMARY KEY (`series_id`, `season_id`)
)
"""
)
""")

print("\nCreating table episodes...")
pool.execute_with_retries(
"""
pool.execute_with_retries("""
CREATE table `episodes` (
`series_id` Int64,
`season_id` Int64,
Expand All @@ -234,8 +226,7 @@ def create_tables(pool: ydb.QuerySessionPool):
`air_date` Date,
PRIMARY KEY (`series_id`, `season_id`, `episode_id`)
)
"""
)
""")


def run(endpoint, database):
Expand Down
25 changes: 8 additions & 17 deletions examples/basic_example_v2/basic_example_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ydb
import basic_example_data


DropTablesQuery = """
DROP TABLE IF EXISTS series;
DROP TABLE IF EXISTS seasons;
Expand Down Expand Up @@ -99,11 +98,9 @@ async def select_simple(pool: ydb.aio.QuerySessionPool):
async def upsert_simple(pool: ydb.aio.QuerySessionPool):
print("\nPerforming UPSERT into episodes...")

await pool.execute_with_retries(
"""
await pool.execute_with_retries("""
UPSERT INTO episodes (series_id, season_id, episode_id, title) VALUES (2, 6, 1, "TBD");
"""
)
""")


async def select_with_parameters(pool: ydb.aio.QuerySessionPool, series_id, season_id, episode_id):
Expand Down Expand Up @@ -196,21 +193,18 @@ async def drop_tables(pool: ydb.aio.QuerySessionPool):

async def create_tables(pool: ydb.aio.QuerySessionPool):
print("\nCreating table series...")
await pool.execute_with_retries(
"""
await pool.execute_with_retries("""
CREATE table `series` (
`series_id` Int64,
`title` Utf8,
`series_info` Utf8,
`release_date` Date,
PRIMARY KEY (`series_id`)
)
"""
)
""")

print("\nCreating table seasons...")
await pool.execute_with_retries(
"""
await pool.execute_with_retries("""
CREATE table `seasons` (
`series_id` Int64,
`season_id` Int64,
Expand All @@ -219,12 +213,10 @@ async def create_tables(pool: ydb.aio.QuerySessionPool):
`last_aired` Date,
PRIMARY KEY (`series_id`, `season_id`)
)
"""
)
""")

print("\nCreating table episodes...")
await pool.execute_with_retries(
"""
await pool.execute_with_retries("""
CREATE table `episodes` (
`series_id` Int64,
`season_id` Int64,
Expand All @@ -233,8 +225,7 @@ async def create_tables(pool: ydb.aio.QuerySessionPool):
`air_date` Date,
PRIMARY KEY (`series_id`, `season_id`, `episode_id`)
)
"""
)
""")


async def run(endpoint, database):
Expand Down
1 change: 0 additions & 1 deletion examples/cloud-function-trivial-example/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import ydb


driver_config = ydb.DriverConfig(
endpoint=os.getenv("YDB_ENDPOINT"),
database=os.getenv("YDB_DATABASE"),
Expand Down
1 change: 0 additions & 1 deletion examples/coordination/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from example_async import run as run_async
import logging


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
1 change: 0 additions & 1 deletion examples/jsondemo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
import jsondemo


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
8 changes: 2 additions & 6 deletions examples/jsondemo/jsondemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def insert_json_rows(pool: ydb.SessionPool, table_path: str, num: int):
inputData.append({"key": i + 1, "jsonb_value": make_json(i)})
qtext = """
DECLARE $input AS List<Struct<key: Int32, jsonb_value: JsonDocument>>;
UPSERT INTO `%s` SELECT * FROM AS_TABLE($input);""" % (
table_path
)
UPSERT INTO `%s` SELECT * FROM AS_TABLE($input);""" % (table_path)

def fun(session: ydb.Session):
session.transaction(ydb.SerializableReadWrite()).execute(
Expand All @@ -61,9 +59,7 @@ def fun(session: ydb.Session):
def find_json_row(pool: ydb.SessionPool, table_path: str, id: int):
qtext = """
DECLARE $key AS Int32; SELECT jsonb_value FROM `%s` WHERE key=$key;
""" % (
table_path
)
""" % (table_path)

def fun(session: ydb.Session):
rs = session.transaction().execute(
Expand Down
1 change: 0 additions & 1 deletion examples/pagination/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
import pagination


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
8 changes: 2 additions & 6 deletions examples/pagination/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def __init__(self, session, path, limit):

$Union = (SELECT * FROM $Part1 UNION ALL SELECT * FROM $Part2);
SELECT * FROM $Union ORDER BY `city`, `number` LIMIT $limit;
""".format(
path=self.path
)
""".format(path=self.path)

self.prepared_next_page_query = self.session.prepare(next_page_query)

Expand All @@ -53,9 +51,7 @@ def get_first_page(self):
SELECT * FROM schools
ORDER BY `city`, `number`
LIMIT $limit;
""".format(
path=self.path
)
""".format(path=self.path)
prepared_query = self.session.prepare(query)
result_sets = self.session.transaction(ydb.SerializableReadWrite()).execute(
prepared_query, {"$limit": self.limit}, commit_tx=True
Expand Down
4 changes: 1 addition & 3 deletions examples/pagination/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def fill_table(session, path):
number,
address
FROM AS_TABLE($schoolsData);
""".format(
path=path
)
""".format(path=path)
prepared_query = session.prepare(query)
session.transaction(ydb.SerializableReadWrite()).execute(
prepared_query,
Expand Down
1 change: 0 additions & 1 deletion examples/query-stats/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import ydb


SESSION_QUERY = "SELECT 1"
TX_QUERY = "SELECT 1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import ydb
from concurrent.futures import TimeoutError


FILL_DATA_QUERY = """
--!syntax_v1
PRAGMA TablePathPrefix("{}");
Expand Down
1 change: 0 additions & 1 deletion examples/static-credentials/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import argparse
from example import run


if __name__ == "__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
Expand Down
1 change: 0 additions & 1 deletion examples/time-series-serverless/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from exception import ValidationError


US_IN_MSEC = 1000


Expand Down
Loading
Loading