|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +echo "Running schema evolution (position) test..." |
| 5 | + |
| 6 | +SCENARIO_DIR="{{SCENARIO_DIR}}" |
| 7 | +INPUT_PATH="${SCENARIO_DIR}/../insert-scan/input.parquet" |
| 8 | + |
| 9 | +# Extract ordered column names from "describe -s" output into a comma-joined string. |
| 10 | +# Each column line looks like: " 1: sepal.length: optional double" |
| 11 | +extract_order() { |
| 12 | + grep -E '^[[:space:]]+[0-9]+: [A-Za-z0-9._]+:' "$1" \ |
| 13 | + | sed -E 's/^[[:space:]]+[0-9]+: ([A-Za-z0-9._]+):.*/\1/' \ |
| 14 | + | paste -s -d, - |
| 15 | +} |
| 16 | + |
| 17 | +assert_order() { |
| 18 | + local label="$1" |
| 19 | + local expected="$2" |
| 20 | + local actual="$3" |
| 21 | + if [ "$expected" != "$actual" ]; then |
| 22 | + echo "FAIL ${label}: expected '${expected}' got '${actual}'" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + echo "OK ${label}: ${actual}" |
| 26 | +} |
| 27 | + |
| 28 | +{{ICE_CLI}} --config {{CLI_CONFIG}} create-namespace ${NAMESPACE_NAME} |
| 29 | +{{ICE_CLI}} --config {{CLI_CONFIG}} insert --create-table ${TABLE_NAME} "file://${INPUT_PATH}" |
| 30 | +echo "OK Inserted data into ${TABLE_NAME}" |
| 31 | + |
| 32 | +{{ICE_CLI}} --config {{CLI_CONFIG}} describe -s ${TABLE_NAME} > /tmp/sepos_initial.txt |
| 33 | +assert_order "initial order" \ |
| 34 | + "sepal.length,sepal.width,petal.length,petal.width,variety" \ |
| 35 | + "$(extract_order /tmp/sepos_initial.txt)" |
| 36 | + |
| 37 | +# --- after --- |
| 38 | +{{ICE_CLI}} --config {{CLI_CONFIG}} alter-table ${TABLE_NAME} \ |
| 39 | + $'[{"op":"add_column","name":"a_after","type":"string","after":"petal.length"}]' |
| 40 | +{{ICE_CLI}} --config {{CLI_CONFIG}} describe -s ${TABLE_NAME} > /tmp/sepos_after.txt |
| 41 | +assert_order "after=petal.length" \ |
| 42 | + "sepal.length,sepal.width,petal.length,a_after,petal.width,variety" \ |
| 43 | + "$(extract_order /tmp/sepos_after.txt)" |
| 44 | + |
| 45 | +# --- before --- |
| 46 | +{{ICE_CLI}} --config {{CLI_CONFIG}} alter-table ${TABLE_NAME} \ |
| 47 | + $'[{"op":"add_column","name":"a_before","type":"string","before":"variety"}]' |
| 48 | +{{ICE_CLI}} --config {{CLI_CONFIG}} describe -s ${TABLE_NAME} > /tmp/sepos_before.txt |
| 49 | +assert_order "before=variety" \ |
| 50 | + "sepal.length,sepal.width,petal.length,a_after,petal.width,a_before,variety" \ |
| 51 | + "$(extract_order /tmp/sepos_before.txt)" |
| 52 | + |
| 53 | +# --- first --- |
| 54 | +{{ICE_CLI}} --config {{CLI_CONFIG}} alter-table ${TABLE_NAME} \ |
| 55 | + $'[{"op":"add_column","name":"a_first","type":"string","first":true}]' |
| 56 | +{{ICE_CLI}} --config {{CLI_CONFIG}} describe -s ${TABLE_NAME} > /tmp/sepos_first.txt |
| 57 | +assert_order "first=true" \ |
| 58 | + "a_first,sepal.length,sepal.width,petal.length,a_after,petal.width,a_before,variety" \ |
| 59 | + "$(extract_order /tmp/sepos_first.txt)" |
| 60 | + |
| 61 | +# --- both after and before: CLI applies after only (before ignored) --- |
| 62 | +{{ICE_CLI}} --config {{CLI_CONFIG}} alter-table ${TABLE_NAME} \ |
| 63 | + $'[{"op":"add_column","name":"bad","type":"string","after":"variety","before":"petal.width"}]' |
| 64 | +{{ICE_CLI}} --config {{CLI_CONFIG}} describe -s ${TABLE_NAME} > /tmp/sepos_conflict.txt |
| 65 | +assert_order "after wins when both after and before set" \ |
| 66 | + "a_first,sepal.length,sepal.width,petal.length,a_after,petal.width,a_before,variety,bad" \ |
| 67 | + "$(extract_order /tmp/sepos_conflict.txt)" |
| 68 | +echo "OK conflicting position: after wins (before ignored)" |
| 69 | + |
| 70 | +# Cleanup |
| 71 | +{{ICE_CLI}} --config {{CLI_CONFIG}} delete-table ${TABLE_NAME} |
| 72 | +{{ICE_CLI}} --config {{CLI_CONFIG}} delete-namespace ${NAMESPACE_NAME} |
| 73 | +echo "OK Cleanup done" |
| 74 | + |
| 75 | +echo "Schema evolution (position) test completed successfully" |
0 commit comments