From 96fcafcd2fbc13cb6e881932e8cdc62d5683adb9 Mon Sep 17 00:00:00 2001 From: Colin Dellow Date: Sat, 10 Mar 2018 13:25:13 -0500 Subject: [PATCH] Add test cases --- parquet/parquet.cc | 25 +++++---- .../queries/014-nulls-like-percent-start.sql | 2 + tests/queries/015-nulls-like-no-match.sql | 1 + tests/queries/016-nulls-like-percent-end.sql | 51 +++++++++++++++++++ tests/queries/017-nulls-like-underscore.sql | 2 + tests/queries/018-string-gt-lt.sql | 3 ++ tests/queries/019-string-gte-lte.sql | 2 + tests/queries/020-string-eq.sql | 2 + tests/queries/021-rowid-and-field-eq.sql | 2 + tests/queries/022-rowid-and-field-ne.sql | 1 + tests/queries/023-int8-eq.sql | 2 + tests/queries/024-int8-lt.sql | 2 + tests/queries/025-int8-lte.sql | 3 ++ tests/queries/026-int8-gt.sql | 2 + tests/queries/027-int8-gte.sql | 3 ++ .../028-int8-rowid-eq-and-field-ne.sql | 1 + tests/queries/029-int64-gte.sql | 3 ++ tests/queries/030-int64-gt.sql | 2 + tests/queries/031-int64-eq.sql | 2 + tests/queries/032-int64-lt.sql | 2 + tests/queries/033-int64-lte.sql | 3 ++ .../034-int64-rowid-eq-and-field-ne.sql | 1 + .../035-int64-rowid-eq-and-field-ne2.sql | 2 + tests/queries/036-double-eq.sql | 2 + tests/queries/037-double-gt.sql | 2 + tests/queries/038-double-gte.sql | 3 ++ tests/queries/039-double-lt.sql | 2 + tests/queries/040-double-lte.sql | 2 + .../queries/041-double-rowid-and-field-ne.sql | 1 + .../042-double-rowid-and-field-ne2.sql | 2 + tests/queries/043-binary-eq.sql | 2 + tests/queries/044-binary-rowid-and-ne.sql | 1 + tests/queries/045-binary-lt.sql | 2 + tests/queries/046-binary-lte.sql | 3 ++ tests/queries/047-binary-gt.sql | 2 + tests/queries/048-binary-gte.sql | 3 ++ tests/test-queries | 4 +- 37 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 tests/queries/014-nulls-like-percent-start.sql create mode 100644 tests/queries/015-nulls-like-no-match.sql create mode 100644 tests/queries/016-nulls-like-percent-end.sql create mode 100644 tests/queries/017-nulls-like-underscore.sql create mode 100644 tests/queries/018-string-gt-lt.sql create mode 100644 tests/queries/019-string-gte-lte.sql create mode 100644 tests/queries/020-string-eq.sql create mode 100644 tests/queries/021-rowid-and-field-eq.sql create mode 100644 tests/queries/022-rowid-and-field-ne.sql create mode 100644 tests/queries/023-int8-eq.sql create mode 100644 tests/queries/024-int8-lt.sql create mode 100644 tests/queries/025-int8-lte.sql create mode 100644 tests/queries/026-int8-gt.sql create mode 100644 tests/queries/027-int8-gte.sql create mode 100644 tests/queries/028-int8-rowid-eq-and-field-ne.sql create mode 100644 tests/queries/029-int64-gte.sql create mode 100644 tests/queries/030-int64-gt.sql create mode 100644 tests/queries/031-int64-eq.sql create mode 100644 tests/queries/032-int64-lt.sql create mode 100644 tests/queries/033-int64-lte.sql create mode 100644 tests/queries/034-int64-rowid-eq-and-field-ne.sql create mode 100644 tests/queries/035-int64-rowid-eq-and-field-ne2.sql create mode 100644 tests/queries/036-double-eq.sql create mode 100644 tests/queries/037-double-gt.sql create mode 100644 tests/queries/038-double-gte.sql create mode 100644 tests/queries/039-double-lt.sql create mode 100644 tests/queries/040-double-lte.sql create mode 100644 tests/queries/041-double-rowid-and-field-ne.sql create mode 100644 tests/queries/042-double-rowid-and-field-ne2.sql create mode 100644 tests/queries/043-binary-eq.sql create mode 100644 tests/queries/044-binary-rowid-and-ne.sql create mode 100644 tests/queries/045-binary-lt.sql create mode 100644 tests/queries/046-binary-lte.sql create mode 100644 tests/queries/047-binary-gt.sql create mode 100644 tests/queries/048-binary-gte.sql diff --git a/parquet/parquet.cc b/parquet/parquet.cc index 80d1a62..5807c6f 100644 --- a/parquet/parquet.cc +++ b/parquet/parquet.cc @@ -277,7 +277,8 @@ static int parquetEof(sqlite3_vtab_cursor *cur){ return 0; } -void debugConstraints(sqlite3_index_info *pIdxInfo, ParquetTable *table, sqlite3_value** argv) { +void debugConstraints(sqlite3_index_info *pIdxInfo, ParquetTable *table, int argc, sqlite3_value** argv) { + printf("debugConstraints, argc=%d\n", argc); for(int i = 0; i < pIdxInfo->nConstraint; i++) { std::string valueStr = "?"; if(argv != NULL) { @@ -345,14 +346,16 @@ static int parquetFilter( ){ ParquetCursor* cursor = ((sqlite3_vtab_cursor_parquet*)cur)->cursor; printf("xFilter: idxNum=%d, idxStr=%lu, argc=%d\n", idxNum, (long unsigned int)idxStr, argc); - debugConstraints((sqlite3_index_info*)idxStr, cursor->getTable(), argv); + debugConstraints((sqlite3_index_info*)idxStr, cursor->getTable(), argc, argv); cursor->reset(); return parquetNext(cur); } /* -* Only a forward full table scan is supported. xBestIndex is mostly -* a no-op. +* We'll always indicate to SQLite that we prefer it to use an index so that it will +* pass additional context to xFilter, which we may or may not use. +* +* We copy the sqlite3_index_info structure, as is, into idxStr for later use. */ static int parquetBestIndex( sqlite3_vtab *tab, @@ -361,18 +364,20 @@ static int parquetBestIndex( ParquetTable* table = ((sqlite3_vtab_parquet*)tab)->table; printf("xBestIndex: nConstraint=%d, nOrderBy=%d\n", pIdxInfo->nConstraint, pIdxInfo->nOrderBy); - debugConstraints(pIdxInfo, table, NULL); + debugConstraints(pIdxInfo, table, 0, NULL); - if((pIdxInfo->nConstraint == 0 && pIdxInfo->nOrderBy == 0)) { + if(pIdxInfo->nConstraint == 0) { pIdxInfo->estimatedCost = 1000000000000; pIdxInfo->idxNum = 0; - pIdxInfo->estimatedRows = 10000; } else { pIdxInfo->estimatedCost = 1; pIdxInfo->idxNum = 1; - pIdxInfo->estimatedRows = 100000; - pIdxInfo->aConstraintUsage[0].argvIndex = 1; -// pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE; + for(int i = 0; i < pIdxInfo->nConstraint; i++) { + pIdxInfo->aConstraintUsage[i].argvIndex = i + 1; + } + + // TODO: consider setting this when querying by rowid? Unclear if that's implied. + // pIdxInfo->idxFlags = SQLITE_INDEX_SCAN_UNIQUE; } printf("idx %d has cost %f\n", pIdxInfo->idxNum, pIdxInfo->estimatedCost); diff --git a/tests/queries/014-nulls-like-percent-start.sql b/tests/queries/014-nulls-like-percent-start.sql new file mode 100644 index 0000000..d5c5683 --- /dev/null +++ b/tests/queries/014-nulls-like-percent-start.sql @@ -0,0 +1,2 @@ +select string_7, string_8 from nulls where string_8 like '%0' +0|000 diff --git a/tests/queries/015-nulls-like-no-match.sql b/tests/queries/015-nulls-like-no-match.sql new file mode 100644 index 0000000..8f21f2b --- /dev/null +++ b/tests/queries/015-nulls-like-no-match.sql @@ -0,0 +1 @@ +select string_7, string_8 from nulls where string_8 like '0' diff --git a/tests/queries/016-nulls-like-percent-end.sql b/tests/queries/016-nulls-like-percent-end.sql new file mode 100644 index 0000000..8e75c05 --- /dev/null +++ b/tests/queries/016-nulls-like-percent-end.sql @@ -0,0 +1,51 @@ +select string_7, string_8 from nulls where string_8 like '0%' +0|000 +1|001 +2|002 +3|003 +4|004 +5|005 +6|006 +7|007 +8|008 +9|009 +|021 +|023 +|025 +|027 +|029 +|031 +|033 +|035 +|037 +|039 +|041 +|043 +|045 +|047 +|049 +|051 +|053 +|055 +|057 +|059 +|061 +|063 +|065 +|067 +|069 +|071 +|073 +|075 +|077 +|079 +|081 +|083 +|085 +|087 +|089 +|091 +|093 +|095 +|097 +|099 diff --git a/tests/queries/017-nulls-like-underscore.sql b/tests/queries/017-nulls-like-underscore.sql new file mode 100644 index 0000000..560419d --- /dev/null +++ b/tests/queries/017-nulls-like-underscore.sql @@ -0,0 +1,2 @@ +select string_7, string_8 from nulls where string_8 like '0_0' +0|000 diff --git a/tests/queries/018-string-gt-lt.sql b/tests/queries/018-string-gt-lt.sql new file mode 100644 index 0000000..626e080 --- /dev/null +++ b/tests/queries/018-string-gt-lt.sql @@ -0,0 +1,3 @@ +select string_8 from nulls where string_8 > '010' and string_8 < '024' +021 +023 diff --git a/tests/queries/019-string-gte-lte.sql b/tests/queries/019-string-gte-lte.sql new file mode 100644 index 0000000..42e74f3 --- /dev/null +++ b/tests/queries/019-string-gte-lte.sql @@ -0,0 +1,2 @@ +select string_8 from nulls where string_8 >= '021' and string_8 <= '021' +021 diff --git a/tests/queries/020-string-eq.sql b/tests/queries/020-string-eq.sql new file mode 100644 index 0000000..72a52bd --- /dev/null +++ b/tests/queries/020-string-eq.sql @@ -0,0 +1,2 @@ +select string_8 from nulls where string_8 = '021' +021 diff --git a/tests/queries/021-rowid-and-field-eq.sql b/tests/queries/021-rowid-and-field-eq.sql new file mode 100644 index 0000000..7645d57 --- /dev/null +++ b/tests/queries/021-rowid-and-field-eq.sql @@ -0,0 +1,2 @@ +select string_8 from nulls where rowid = 21 and string_8 = '021' +021 diff --git a/tests/queries/022-rowid-and-field-ne.sql b/tests/queries/022-rowid-and-field-ne.sql new file mode 100644 index 0000000..d5aa9f2 --- /dev/null +++ b/tests/queries/022-rowid-and-field-ne.sql @@ -0,0 +1 @@ +select string_8 from nulls where rowid = 21 and string_8 <> '021' diff --git a/tests/queries/023-int8-eq.sql b/tests/queries/023-int8-eq.sql new file mode 100644 index 0000000..e2dbe40 --- /dev/null +++ b/tests/queries/023-int8-eq.sql @@ -0,0 +1,2 @@ +select int8_1 from nulls where int8_1 = 30 +30 diff --git a/tests/queries/024-int8-lt.sql b/tests/queries/024-int8-lt.sql new file mode 100644 index 0000000..06a3fa6 --- /dev/null +++ b/tests/queries/024-int8-lt.sql @@ -0,0 +1,2 @@ +select int8_1 from nulls where int8_1 < -46 +-48 diff --git a/tests/queries/025-int8-lte.sql b/tests/queries/025-int8-lte.sql new file mode 100644 index 0000000..791cf1a --- /dev/null +++ b/tests/queries/025-int8-lte.sql @@ -0,0 +1,3 @@ +select int8_1 from nulls where int8_1 <= -46 +-46 +-48 diff --git a/tests/queries/026-int8-gt.sql b/tests/queries/026-int8-gt.sql new file mode 100644 index 0000000..d41ae46 --- /dev/null +++ b/tests/queries/026-int8-gt.sql @@ -0,0 +1,2 @@ +select int8_1 from nulls where int8_1 > 49 +50 diff --git a/tests/queries/027-int8-gte.sql b/tests/queries/027-int8-gte.sql new file mode 100644 index 0000000..231f425 --- /dev/null +++ b/tests/queries/027-int8-gte.sql @@ -0,0 +1,3 @@ +select int8_1 from nulls where int8_1 >= 49 +50 +49 diff --git a/tests/queries/028-int8-rowid-eq-and-field-ne.sql b/tests/queries/028-int8-rowid-eq-and-field-ne.sql new file mode 100644 index 0000000..57fa9fa --- /dev/null +++ b/tests/queries/028-int8-rowid-eq-and-field-ne.sql @@ -0,0 +1 @@ +select int8_1 from nulls where rowid = 66 and int8_1 <> -16 diff --git a/tests/queries/029-int64-gte.sql b/tests/queries/029-int64-gte.sql new file mode 100644 index 0000000..8aa1b7a --- /dev/null +++ b/tests/queries/029-int64-gte.sql @@ -0,0 +1,3 @@ +select int64_4 from nulls where int64_4 >= 49000000000 +50000000000 +49000000000 diff --git a/tests/queries/030-int64-gt.sql b/tests/queries/030-int64-gt.sql new file mode 100644 index 0000000..5597ca8 --- /dev/null +++ b/tests/queries/030-int64-gt.sql @@ -0,0 +1,2 @@ +select int64_4 from nulls where int64_4 > 49000000000 +50000000000 diff --git a/tests/queries/031-int64-eq.sql b/tests/queries/031-int64-eq.sql new file mode 100644 index 0000000..71d0bfd --- /dev/null +++ b/tests/queries/031-int64-eq.sql @@ -0,0 +1,2 @@ +select int64_4 from nulls where int64_4 = 49000000000 +49000000000 diff --git a/tests/queries/032-int64-lt.sql b/tests/queries/032-int64-lt.sql new file mode 100644 index 0000000..a3c41d4 --- /dev/null +++ b/tests/queries/032-int64-lt.sql @@ -0,0 +1,2 @@ +select int64_4 from nulls where int64_4 < -47000000000 +-49000000000 diff --git a/tests/queries/033-int64-lte.sql b/tests/queries/033-int64-lte.sql new file mode 100644 index 0000000..354cbd4 --- /dev/null +++ b/tests/queries/033-int64-lte.sql @@ -0,0 +1,3 @@ +select int64_4 from nulls where int64_4 <= -47000000000 +-47000000000 +-49000000000 diff --git a/tests/queries/034-int64-rowid-eq-and-field-ne.sql b/tests/queries/034-int64-rowid-eq-and-field-ne.sql new file mode 100644 index 0000000..a8ed766 --- /dev/null +++ b/tests/queries/034-int64-rowid-eq-and-field-ne.sql @@ -0,0 +1 @@ +select int64_4 from nulls where rowid = 57 and int64_4 <> -7000000000 diff --git a/tests/queries/035-int64-rowid-eq-and-field-ne2.sql b/tests/queries/035-int64-rowid-eq-and-field-ne2.sql new file mode 100644 index 0000000..73f8642 --- /dev/null +++ b/tests/queries/035-int64-rowid-eq-and-field-ne2.sql @@ -0,0 +1,2 @@ +select int64_4 from nulls where rowid = 57 and int64_4 <> -8000000000 +-7000000000 diff --git a/tests/queries/036-double-eq.sql b/tests/queries/036-double-eq.sql new file mode 100644 index 0000000..bbd4eb3 --- /dev/null +++ b/tests/queries/036-double-eq.sql @@ -0,0 +1,2 @@ +select printf('%.4f', double_6) as double_6 from nulls where double_6 = 100.0 +100.0000 diff --git a/tests/queries/037-double-gt.sql b/tests/queries/037-double-gt.sql new file mode 100644 index 0000000..8d8859b --- /dev/null +++ b/tests/queries/037-double-gt.sql @@ -0,0 +1,2 @@ +select printf('%.4f', double_6) as double_6 from nulls where double_6 > 99 +100.0000 diff --git a/tests/queries/038-double-gte.sql b/tests/queries/038-double-gte.sql new file mode 100644 index 0000000..dd82528 --- /dev/null +++ b/tests/queries/038-double-gte.sql @@ -0,0 +1,3 @@ +select printf('%.4f', double_6) as double_6 from nulls where double_6 >= 50 +100.0000 +50.0000 diff --git a/tests/queries/039-double-lt.sql b/tests/queries/039-double-lt.sql new file mode 100644 index 0000000..463e71e --- /dev/null +++ b/tests/queries/039-double-lt.sql @@ -0,0 +1,2 @@ +select printf('%.4f', double_6) as double_6 from nulls where double_6 < 100.0 order by double_6 desc limit 1 +50.0000 diff --git a/tests/queries/040-double-lte.sql b/tests/queries/040-double-lte.sql new file mode 100644 index 0000000..eddcfaf --- /dev/null +++ b/tests/queries/040-double-lte.sql @@ -0,0 +1,2 @@ +select printf('%.4f', double_6) from nulls where double_6 <= 100.0 order by double_6 desc limit 1 +100.0000 diff --git a/tests/queries/041-double-rowid-and-field-ne.sql b/tests/queries/041-double-rowid-and-field-ne.sql new file mode 100644 index 0000000..4b554dd --- /dev/null +++ b/tests/queries/041-double-rowid-and-field-ne.sql @@ -0,0 +1 @@ +select printf('%.4f', double_6) from nulls where rowid = 0 and double_6 <> 100 diff --git a/tests/queries/042-double-rowid-and-field-ne2.sql b/tests/queries/042-double-rowid-and-field-ne2.sql new file mode 100644 index 0000000..cfcdfed --- /dev/null +++ b/tests/queries/042-double-rowid-and-field-ne2.sql @@ -0,0 +1,2 @@ +select printf('%.4f', double_6) from nulls where rowid = 0 and double_6 <> 101 +100.0000 diff --git a/tests/queries/043-binary-eq.sql b/tests/queries/043-binary-eq.sql new file mode 100644 index 0000000..c83a9dd --- /dev/null +++ b/tests/queries/043-binary-eq.sql @@ -0,0 +1,2 @@ +select rowid from nulls where binary_10 = x'01'; +1 diff --git a/tests/queries/044-binary-rowid-and-ne.sql b/tests/queries/044-binary-rowid-and-ne.sql new file mode 100644 index 0000000..688e4e1 --- /dev/null +++ b/tests/queries/044-binary-rowid-and-ne.sql @@ -0,0 +1 @@ +select rowid from nulls where rowid = 1 and binary_10 <> x'01'; diff --git a/tests/queries/045-binary-lt.sql b/tests/queries/045-binary-lt.sql new file mode 100644 index 0000000..4123e1f --- /dev/null +++ b/tests/queries/045-binary-lt.sql @@ -0,0 +1,2 @@ +select rowid from nulls where binary_10 < x'01'; +0 diff --git a/tests/queries/046-binary-lte.sql b/tests/queries/046-binary-lte.sql new file mode 100644 index 0000000..5b97f2b --- /dev/null +++ b/tests/queries/046-binary-lte.sql @@ -0,0 +1,3 @@ +select rowid from nulls where binary_10 <= x'01' order by 1; +0 +1 diff --git a/tests/queries/047-binary-gt.sql b/tests/queries/047-binary-gt.sql new file mode 100644 index 0000000..5e58c8c --- /dev/null +++ b/tests/queries/047-binary-gt.sql @@ -0,0 +1,2 @@ +select rowid from nulls where binary_10 > x'61'; +99 diff --git a/tests/queries/048-binary-gte.sql b/tests/queries/048-binary-gte.sql new file mode 100644 index 0000000..a50206f --- /dev/null +++ b/tests/queries/048-binary-gte.sql @@ -0,0 +1,3 @@ +select rowid from nulls where binary_10 >= x'61' order by 1; +97 +99 diff --git a/tests/test-queries b/tests/test-queries index 2de0d26..6c9e95f 100755 --- a/tests/test-queries +++ b/tests/test-queries @@ -15,7 +15,8 @@ run_query() { CREATE VIRTUAL TABLE nulls USING parquet('$root/parquet-generator/100-rows-nulls.parquet'); CREATE VIRTUAL TABLE no_nulls1 USING parquet('$root/parquet-generator/100-rows-1.parquet'); CREATE VIRTUAL TABLE no_nulls2 USING parquet('$root/parquet-generator/100-rows-10.parquet'); -$query +$query; +.output EOF } @@ -39,6 +40,7 @@ main() { fi if [ "$(cat testcases.txt | wc -l)" == "1" ]; then + set -x gdb -ex run --args "$root"/sqlite/sqlite3 -init testcase-cmds.txt else while read -r file; do