github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_generated_columns/run.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright 2020 PingCAP, Inc.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  set -eux
    17  
    18  run_sql "SELECT CONCAT('SET GLOBAL time_zone=''', @@time_zone, ''', GLOBAL default_week_format=', @@default_week_format, ', GLOBAL block_encryption_mode=''', @@block_encryption_mode, ''';') cmd;"
    19  UNDO_CMD=$(read_result)
    20  undo_set_globals() {
    21      run_sql "$UNDO_CMD"
    22  }
    23  trap undo_set_globals EXIT
    24  
    25  # There is normally a 2 second delay between these SET GLOBAL statements returns
    26  # and the changes are actually effective. So we have this check-and-retry loop
    27  # below to ensure Lightning gets our desired global vars.
    28  run_sql "SET GLOBAL time_zone='-08:00', GLOBAL default_week_format=4, GLOBAL block_encryption_mode='aes-256-cbc'"
    29  for i in $(seq 3); do
    30      sleep 1
    31      run_sql "SELECT CONCAT(@@time_zone, ',', @@default_week_format, ',', @@block_encryption_mode) res"
    32      if [ "$(read_result)" = '-08:00,4,aes-256-cbc' ]; then
    33          break
    34      fi
    35  done
    36  
    37  for BACKEND in 'local' 'tidb' 'importer'; do
    38      if [ "$BACKEND" = 'local' ]; then
    39          check_cluster_version 4 0 0 'local backend' || continue
    40      fi
    41  
    42      run_sql 'DROP DATABASE IF EXISTS gencol'
    43  
    44      run_lightning --backend $BACKEND
    45  
    46      run_sql 'ADMIN CHECK TABLE gencol.nested'
    47      run_sql 'SELECT * FROM gencol.nested WHERE a = 100'
    48      check_contains 'a: 100'
    49      check_contains 'b: 101'
    50      check_contains 'c: 102'
    51      check_contains 'd: 103'
    52      check_contains 'e: 104'
    53      check_contains 'f: 105'
    54      run_sql 'SELECT * FROM gencol.nested WHERE f = 1005'
    55      check_contains 'a: 1000'
    56      check_contains 'b: 1001'
    57      check_contains 'c: 1002'
    58      check_contains 'd: 1003'
    59      check_contains 'e: 1004'
    60      check_contains 'f: 1005'
    61  
    62      run_sql 'SELECT * FROM gencol.various_types' --binary-as-hex
    63      check_contains 'int64: 3'
    64      check_contains 'uint64: 5764801'
    65      check_contains 'float32: 0.5625'
    66      check_contains 'float64: 5e222'
    67      check_contains 'string: 6ad8402ba6610f04d3ec5c9875489a7bc8e259c5'
    68      check_contains 'bytes: 0x6AD8402BA6610F04D3EC5C9875489A7BC8E259C5'
    69      check_contains 'decimal: 1234.5678'
    70      check_contains 'duration: 01:02:03'
    71      check_contains 'enum: c'
    72      check_contains 'bit: 0x03'
    73      check_contains 'set: c'
    74      check_contains 'time: 1987-06-05 04:03:02.100'
    75      check_contains 'json: {"6ad8402ba6610f04d3ec5c9875489a7bc8e259c5": 0.5625}'
    76      check_contains 'aes: 0xA876B03CFC8AF93D22D19E2220BD2375'
    77      # FIXME: test below disabled due to pingcap/tidb#21510
    78      # check_contains 'week: 6'
    79      check_contains 'tz: 1969-12-31 16:00:01'
    80  
    81      run_sql 'ADMIN CHECK TABLE gencol.virtual_only'
    82      run_sql 'SELECT * FROM gencol.virtual_only WHERE id = 30'
    83      check_contains 'id_plus_1: 31'
    84      check_contains 'id_plus_2: 32'
    85      run_sql 'SELECT * FROM gencol.virtual_only WHERE id_plus_2 = 42'
    86      check_contains 'id: 40'
    87      check_contains 'id_plus_1: 41'
    88  
    89      run_sql 'ADMIN CHECK TABLE gencol.expr_index'
    90      run_sql 'SELECT /*+ use_index(gencol.expr_index, idx_lower_b) */ * FROM gencol.expr_index WHERE lower(b) = "cdsfds"'
    91      check_contains 'id: 2'
    92      check_contains 'a: ABC'
    93      check_contains 'b: CDSFDS'
    94  done