Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
tests: add generated columns test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Dec 2, 2020
1 parent 3ffd5eb commit 8dad811
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/_utils/run_sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
set -eu
TEST_DIR=/tmp/lightning_test_result

echo "[$(date)] Executing SQL: $1" > "$TEST_DIR/sql_res.$TEST_NAME.txt"
echo "[$(date)] Executing SQL: ${*: -1:1}" > "$TEST_DIR/sql_res.$TEST_NAME.txt"
mysql -uroot -h127.0.0.1 -P4000 \
--ssl-ca="$TEST_DIR/tls/ca.pem" \
--ssl-cert="$TEST_DIR/tls/curl.pem" \
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/generated_columns/data/gencol-schema-create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create schema gencol;
7 changes: 7 additions & 0 deletions tests/generated_columns/data/gencol.nested-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
create table nested (
a int not null primary key,
b int as (a + 1) virtual unique,
c int as (b + 1) stored unique,
d int as (c + 1) virtual unique,
e int as (d + 1) stored unique
);
1 change: 1 addition & 0 deletions tests/generated_columns/data/gencol.nested.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into nested (a) values (1), (10), (100), (1000);
15 changes: 15 additions & 0 deletions tests/generated_columns/data/gencol.various_types-schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
create table various_types (
int64 bigint as (1 + 2) stored,
uint64 bigint unsigned as (pow(7, 8)) stored, -- 5764801
float32 float as (9 / 16) stored,
float64 double as (5e222) stored,
string text as (sha1(repeat('x', uint64))) stored, -- '6ad8402ba6610f04d3ec5c9875489a7bc8e259c5'
bytes blob as (unhex(string)) stored,
`decimal` decimal(8, 4) as (1234.5678) stored,
duration time as ('1:2:3') stored,
enum enum('a','b','c') as ('c') stored,
bit bit(4) as (int64) stored,
`set` set('a','b','c') as (enum) stored,
time timestamp(3) as ('1987-06-05 04:03:02.100') stored,
json json as (json_object(string, float32)) stored
);
1 change: 1 addition & 0 deletions tests/generated_columns/data/gencol.various_types.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into various_types () values ();
48 changes: 48 additions & 0 deletions tests/generated_columns/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh
#
# Copyright 2020 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

for BACKEND in 'tidb' 'importer' 'local'; do
if [ "$BACKEND" = 'local' ]; then
check_cluster_version 4 0 0 'local backend' || continue
fi

run_sql 'DROP DATABASE IF EXISTS gencol'

run_lightning --backend $BACKEND

run_sql 'SELECT * FROM gencol.nested WHERE a = 100'
check_contains 'a: 100'
check_contains 'b: 101'
check_contains 'c: 102'
check_contains 'd: 103'
check_contains 'e: 104'

run_sql --binary-as-hex 'SELECT * FROM gencol.various_types'
check_contains 'int64: 3'
check_contains 'uint64: 5764801'
check_contains 'float32: 0.5625'
check_contains 'float64: 5e222'
check_contains 'string: 6ad8402ba6610f04d3ec5c9875489a7bc8e259c5'
check_contains 'bytes: 0x6AD8402BA6610F04D3EC5C9875489A7BC8E259C5'
check_contains 'decimal: 1234.5678'
check_contains 'duration: 01:02:03'
check_contains 'enum: c'
check_contains 'bit: 0x03'
check_contains 'set: c'
check_contains 'time: 1987-06-05 04:03:02.100'
check_contains 'json: {"6ad8402ba6610f04d3ec5c9875489a7bc8e259c5": 0.5625}'
done

0 comments on commit 8dad811

Please sign in to comment.