#!/bin/bash
r='rasql --user rasadmin --passwd rasadmin'


$r -q 'drop collection test_1' > /dev/null 2>&1

echo "Create first type"
$r -q 'drop type type1_set' > /dev/null 2>&1
$r -q 'drop type type1_mdd' > /dev/null 2>&1
$r -q 'drop type type1_base' > /dev/null 2>&1
$r -q 'CREATE TYPE type1_base AS ( b1 char, b2 char, b3 char)' > /dev/null
$r -q 'CREATE TYPE type1_mdd AS type1_base MDARRAY [a0, a1]' > /dev/null
$r -q 'CREATE TYPE type1_set AS SET (type1_mdd)' > /dev/null

echo "Create second type"
$r -q 'drop type type2_set' > /dev/null 2>&1
$r -q 'drop type type2_mdd' > /dev/null 2>&1
$r -q 'drop type type2_base' > /dev/null 2>&1
$r -q 'CREATE TYPE type2_base AS ( b3 char, b2 char, b1 char)' > /dev/null
$r -q 'CREATE TYPE type2_mdd AS type2_base MDARRAY [a0, a1]' > /dev/null
$r -q 'CREATE TYPE type2_set AS SET (type2_mdd)' > /dev/null

echo "Create a collection based on type_2 (note: it should be in order: b3, b2, b1)"
$r -q 'CREATE COLLECTION test_1 type2_set' > /dev/null
$r -q 'INSERT INTO test_1 VALUES <[0:0,0:0] {0c,1c,2c}>' > /dev/null

echo "Check the band names of the test coverage"
$r -q 'SELECT dbinfo(c) from test_1 as c' --out string --quiet

echo "Expected output: 0, 1, 2"
$r -q 'SELECT csv(c.b3) from test_1 as c' --out string --quiet
$r -q 'SELECT csv(c.b2) from test_1 as c' --out string --quiet
$r -q 'SELECT csv(c.b1) from test_1 as c' --out string --quiet
