Skip to content

Instantly share code, notes, and snippets.

View apstndb's full-sized avatar

apstndb

View GitHub Profile
from google.cloud import bigquery
import google.auth
def query():
credentials, project = google.auth.default( scopes=[ "https://www.googleapis.com/auth/bigquery.readonly"] )
client = bigquery.Client(credentials=credentials, project=project)
query = "SELECT 1"
results = client.query(query, api_method=bigquery.enums.QueryApiMethod.QUERY).result()
for row in results:
@apstndb
apstndb / Google Cloud document feedbacks.md
Last active May 9, 2025 17:13
Google Cloud document feedbacks
@apstndb
apstndb / main.go
Created September 12, 2024 15:42
memefish cloud-spanner-emulator test runner
package main
import (
"context"
"encoding/csv"
"flag"
"fmt"
parser "github.com/cloudspannerecosystem/memefish"
"github.com/cloudspannerecosystem/memefish/token"
"log"
SELECT SUBSTR(TO_HEX(x), 0, 8), SUBSTR(TO_HEX(x), 0, 16)
FROM(SELECT SHA256(CAST(FirstName AS BYTES)) @{DISABLE_INLINE=FALSE} AS x FROM Singers LIMIT 1)
SELECT SUBSTR(TO_HEX(x), 0, 8), SUBSTR(TO_HEX(x), 0, 16)
FROM(SELECT SHA256(CAST(FirstName AS BYTES)) @{DISABLE_INLINE=TRUE} AS x FROM Singers LIMIT 1)
$ export PROJECT_ID=gcpug-public-spanner INSTANCE_ID=merpay-sponsored-instance DATABASE_ID=apstndb-sampledb-with-data-idx
$ sh show-schema-tree.sh
Concerts
Singers
  Albums
    Songs
    SongsBySingerAlbumSongNameDesc on Songs
SongGenres
AlbumsByAlbumTitle on Albums
@apstndb
apstndb / 0_render_spanner_plan_using_jq.md
Last active October 5, 2020 11:17
Render Cloud Spanner Query Plan using jq
$ gcloud spanner databases execute-sql --project=${PROJECT_ID} --instance=${INSTANCE_ID} ${DATABASE_ID} \
     --sql "$(cat input.sql)" --query-mode=PLAN --format=json | jq -r -f plan.jq
 *0 Distributed Union
 *1   Distributed Cross Apply
  2     Create Batch
  3       Local Distributed Union
  4         Compute Struct
 *5           FilterScan
  6             Index Scan (Index: SongsBySongName)

Unofficial Cloud Spanner operator collection

Query execution operators にはドキュメンテーションされていない operator もあり、 metadata やそれぞれの child links についてもほぼ解説されていないためここにまとめる。

対象: 実行計画を可視化や解析のために処理するツール作成者や、含まれる情報全てをクエリの理解に役立てたいと考えるユーザ

TODO: Metadata や ChildLinks の表の形式化を進める。

実行計画の構造

$ ./go2go run main.go2
true
$ ./go2go translate main.go2
$ cat main.go
// Code generated by go2go; DO NOT EDIT.