File: multi_statement_parsing.cpp

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (30 lines) | stat: -rw-r--r-- 1,084 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "catch.hpp"
#include "test_helpers.hpp"

using namespace duckdb;
using namespace std;

// This test that the parser keeps statements in the right order, also when a multi-statement (i.e. a PIVOT is included
// See https://github.com/duckdb/duckdb/issues/18710
TEST_CASE("Parsing multiple statements including a PIVOT in one go results in a correctly ordered list", "[pivot][.]") {
	DuckDB db(nullptr);
	Connection con(db);
	auto query = "PIVOT (SELECT 'a' AS col) ON col using first(col);SELECT 42;";

	// Check that the SELECT 42 statement is last in the parsed statements list
	auto statements = con.context->ParseStatements(query);
	REQUIRE(statements.size() == 3);
	// REQUIRE(statements.back()->query == "SELECT 42;");

	// Execute the query
	auto result = con.Query(query);

	// We expect two results
	REQUIRE(result);
	REQUIRE(result->next);
	REQUIRE(result->next->next == nullptr);
	// The first result should be that of the PIVOT statement
	REQUIRE(CHECK_COLUMN(result, 0, {"a"}));
	// The second result should be 42
	REQUIRE(CHECK_COLUMN(result->next, 0, {42}));
}