Run memefish test cases in spansql.
https://github.com/cloudspannerecosystem/memefish/tree/main/testdata/input
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)
https://issuetracker.google.com/issues/35905569#comment111
DECLARE v1 INT64 DEFAULT 123;
DECLARE v2 INT64 DEFAULT 123;
BEGIN
SET v1 = @v1;
SET v2 = @v2;
EXCEPTION WHEN ERROR THEN
-- nop
$ 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
$ 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)
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.
import "list" | |
a: [{id: 1}, {id: 2}] | |
b: [{id: 1}, {id: 1}] | |
c: [{id: 1}, {id: 2}, {id: 2}] | |
a_ids:: [x.id for x in a] | |
a_unique: list.UniqueItems(a_ids) | |
unique :: { |
CREATE TEMP FUNCTION typeof_literal(input STRING) | |
AS ( | |
CASE | |
-- Process NUMERIC, DATE, DATETIME, TIME, TIMESTAMP, | |
WHEN REGEXP_CONTAINS(input, r'^[A-Z]+ "') THEN REGEXP_EXTRACT(input, r'^([A-Z]+) "') | |
WHEN REGEXP_CONTAINS(input, r'^-?[0-9]*$') THEN 'INT64' | |
WHEN REGEXP_CONTAINS(input, r'^(-?[0-9]+[.e].*|CAST\("([^"]*)" AS FLOAT64\))$') THEN 'FLOAT64' | |
WHEN input IN ('true', 'false') THEN 'BOOL' | |
WHEN input LIKE '"%' THEN 'STRING' | |
WHEN input LIKE 'b"%' THEN 'BYTES' |