Tsurugi DBからデータを出力する
公式
SQLで
tanzawa/modules/tgsql/README.md at master · project-tsurugi/tanzawa
> cat select.sql
select * from test_table;
> tgsql -c ipc://tsurugi --script select.sql
[main] INFO com.tsurugidb.tgsql.core.TgsqlRunner - establishing connection: ipc://tsurugi
[main] INFO com.tsurugidb.tgsql.core.TgsqlRunner - start processing script
// {"columns":[{"name":"id","label":"id","type":"INT4","dimension":0}]}
{"id":1}
{"id":2}
{"id":3}
{"id":4}
tgdumpで
tanzawa/modules/tgdump at master · project-tsurugi/tanzawa
Parquet
> mkdir result
> tgdump test_table --to result --connection ipc://tsurugi
> ls result/test_table/
d1735190942_0_0.parquet d1735190942_1_0.parquet
> cat look.py
import sys
import pyarrow.parquet as pq
if len(sys.argv) < 2:
print("Usage: python script.py <folder_path>")
sys.exit(1)
folder_path = sys.argv[1]
if not os.path.exists(folder_path):
print(f"Error: The folder '{folder_path}' does not exist.")
sys.exit(1)
parquet_files = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith(".parquet")]
if not parquet_files:
print(f"No .parquet files found in folder: {folder_path}")
sys.exit(0)
for file in parquet_files:
print(f"Reading: {file}")
table = pq.read_table(file)
print(table)
> python3 look.py result/test_table
Reading: result/test_table/d1735190942_0_0.parquet
pyarrow.Table
id: int32
----
id: [[1,2,3]]
Reading: result/test_table/d1735190942_1_0.parquet
pyarrow.Table
id: int32
----
id: [[4]]
Embulkで
公式
Embulk Tsurugi入力メモ(Hishidama's Embulk input-tsurugidb Memo)
Maven Central: io.github.hishidama.embulk:embulk-input-tsurugidb
> export emb_ver=0.11.5
> curl -L https://github.com/embulk/embulk/releases/download/v${emb_ver}/embulk-${emb_ver}.jar -o embulk-${emb_ver}.jar
> java -jar embulk-${emb_ver}.jar install io.github.hishidama.embulk:embulk-input-tsurugidb:1.1.0
> cat 2.yml
in:
type:
source: maven
group: io.github.hishidama.embulk
name: tsurugidb
version: 1.1.0
endpoint: ipc://tsurugi
query: select * from test_table
out:
type: stdout
> java -jar embulk-${emb_ver}.jar run 2.yml
3
4
1
2