Skip to content

Commit 7e8502b

Browse files
authored
Switching to stock SQLite shell (duckdb#388)
We now build a statically linked command line interface `duckdb_cli` built from the stock SQLite shell.c sources.
1 parent 2debf14 commit 7e8502b

File tree

19 files changed

+29640
-13714
lines changed

19 files changed

+29640
-13714
lines changed

.travis.yml

+19-10
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ matrix:
3030
script:
3131
- (mkdir -p build/release && cd build/release && cmake -DCMAKE_BUILD_TYPE=Release ../.. && cmake --build .)
3232
- build/release/test/unittest
33+
- python3 tools/shell/shell-test.py build/release/duckdb_cli
3334

3435
after_success:
35-
- python tools/upload-s3.py lib-osx build/release/src/libduckdb.dylib build/release/src/libduckdb_static.a
36+
- python tools/upload-s3.py lib-osx build/release/src/libduckdb.dylib build/release/src/libduckdb_static.a build/release/duckdb_cli
3637

3738

3839
- os: linux
@@ -110,15 +111,17 @@ matrix:
110111

111112

112113
- os: linux
113-
dist: xenial
114+
dist: bionic
114115
name: GCC 9
116+
python: 3.7
115117

116118
addons:
117119
apt:
118120
sources:
119-
- ubuntu-toolchain-r-test
121+
- sourceline: 'ppa:ubuntu-toolchain-r/test'
122+
- sourceline: 'ppa:deadsnakes/ppa'
120123
packages:
121-
- g++-9
124+
- g++-9 python3.7
122125
env:
123126
- MATRIX_EVAL="CC=gcc-9 && CXX=g++-9"
124127
before_install:
@@ -128,12 +131,14 @@ matrix:
128131
- mkdir -p build/release
129132
- (cd build/release && cmake -DCMAKE_BUILD_TYPE=Release ../.. && cmake --build .)
130133
- build/release/test/unittest "*"
134+
- python3.7 tools/shell/shell-test.py build/release/duckdb_cli
131135
- (cd examples/embedded-c; make)
132136
- (cd examples/embedded-c++; make)
133137
- (cd examples/programmatic-querying; make)
134138

139+
135140
after_success:
136-
- python tools/upload-s3.py lib-linux-amd64 build/release/src/libduckdb*.so build/release/src/libduckdb*.a
141+
- python tools/upload-s3.py lib-linux-amd64 build/release/src/libduckdb*.so build/release/src/libduckdb*.a build/release/duckdb_cli
137142

138143

139144
- os: linux
@@ -158,7 +163,7 @@ matrix:
158163
- build/release/test/unittest "*"
159164

160165
after_success:
161-
- python tools/upload-s3.py lib-linux-i386 build/release/src/libduckdb*.so build/release/src/libduckdb*.a
166+
- python tools/upload-s3.py lib-linux-i386 build/release/src/libduckdb*.so build/release/src/libduckdb*.a build/release/duckdb_cli
162167

163168

164169
- os: linux
@@ -207,10 +212,12 @@ matrix:
207212
- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=x64
208213
- cmake --build . --target duckdb --config Release
209214
- cmake --build . --target unittest --config Release
215+
- cmake --build . --target shell --config Release
210216
- test/Release/unittest.exe
217+
- C:/Python37-x64/python.exe tools/shell/shell-test.py Release/duckdb_cli.exe
211218

212219
after_success:
213-
- C:/Python37-x64/python.exe tools/upload-s3.py lib-windows-amd64 src/Release/duckdb.dll
220+
- C:/Python37-x64/python.exe tools/upload-s3.py lib-windows-amd64 src/Release/duckdb.dll Release/duckdb_cli.exe
214221

215222

216223
- os: windows
@@ -227,10 +234,12 @@ matrix:
227234
- cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=Win32
228235
- cmake --build . --target duckdb --config Release
229236
- cmake --build . --target unittest --config Release
237+
- cmake --build . --target shell --config Release
230238
- test/Release/unittest.exe
239+
- C:/Python37-x64/python.exe tools/shell/shell-test.py Release/duckdb_cli.exe
231240

232241
after_success:
233-
- C:/Python37-x64/python.exe tools/upload-s3.py lib-windows-i386 src/Release/duckdb.dll
242+
- C:/Python37-x64/python.exe tools/upload-s3.py lib-windows-i386 src/Release/duckdb.dll Release/duckdb_cli.exe
234243

235244

236245
- os: linux
@@ -380,8 +389,8 @@ matrix:
380389
before_install:
381390
- choco install python3 --version 3.7.3 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python37"
382391
- choco install python3 --version 3.7.3 --sidebyside -y --force --params "/InstallDir:C:\Python37-x64"
383-
# - choco install python3 --version 3.6.8 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python36"
384-
# - choco install python3 --version 3.6.8 --sidebyside -y --force --params "/InstallDir:C:\Python36-x64"
392+
- choco install python3 --version 3.6.8 --sidebyside -y --force --params "/InstallDir:C:\Python36-x64"
393+
- choco install python3 --version 3.6.8 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python36"
385394
- choco install python2 --version 2.7.16 --sidebyside -y --forcex86 --force --params "/InstallDir:C:\Python27"
386395
- choco install python2 --version 2.7.16 --sidebyside -y --force --params "/InstallDir:C:\Python27-x64"
387396
- choco install curl -y --force

CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ if(${EXPLICIT_EXCEPTIONS})
7474
set(CXX_EXTRA "${CXX_EXTRA} -fexceptions")
7575
endif()
7676

77+
execute_process(COMMAND git
78+
log
79+
-1
80+
--format=%h
81+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
82+
OUTPUT_VARIABLE GIT_COMMIT_HASH
83+
OUTPUT_STRIP_TRAILING_WHITESPACE)
84+
add_definitions(-DDUCKDB_SOURCE_ID="\""${GIT_COMMIT_HASH}"\"")
85+
86+
7787
option(AMALGAMATION_BUILD
7888
"Build from the amalgamation files, rather than from the normal sources."
7989
FALSE)
@@ -201,8 +211,8 @@ add_subdirectory(third_party)
201211

202212
if(NOT LEAN)
203213
add_subdirectory(test)
214+
add_subdirectory(tools)
204215
if(NOT WIN32)
205-
add_subdirectory(tools)
206216
add_subdirectory(benchmark)
207217
endif()
208218
endif()

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DuckDB requires [CMake](https://cmake.org) to be installed and a `C++11` complia
1515
Run `make` in the root directory to compile the sources. For development, use `make debug` to build a non-optimized debug version. You may run `make unit` and `make allunit` to verify that your version works properly after making changes.
1616

1717
# Usage
18-
A command line utility based on `sqlite3` can be found in either `build/release/tools/shell/shell` (release, the default) or `build/debug/tools/shell/shell` (debug).
18+
A command line utility based on `sqlite3` can be found in either `build/release/duckdb_cli` (release, the default) or `build/debug/duckdb_cli` (debug).
1919

2020
# Embedding
2121
As DuckDB is an embedded database, there is no database server to launch or client to connect to a running server. However, the database server can be embedded directly into an application using the C or C++ bindings. The main build process creates the shared library `build/release/src/libduckdb.[so|dylib|dll]` that can be linked against. A static library is built as well.

benchmark/imdb/imdb.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,7 @@ FINISH_BENCHMARK(IMDBQ112);
475475
DUCKDB_BENCHMARK(IMDBQ113, "[imdb]")
476476
IMDB_QUERY_BODY(113);
477477
FINISH_BENCHMARK(IMDBQ113);
478+
479+
DUCKDB_BENCHMARK(IMDBQ114, "[imdb]")
480+
IMDB_QUERY_BODY(114);
481+
FINISH_BENCHMARK(IMDBQ114);

src/function/table/sqlite_functions.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#include "duckdb/function/table/sqlite_functions.hpp"
2+
#include "duckdb/parser/parsed_data/create_view_info.hpp"
3+
#include "duckdb/parser/query_node/select_node.hpp"
4+
#include "duckdb/parser/expression/star_expression.hpp"
5+
#include "duckdb/parser/tableref/table_function_ref.hpp"
6+
#include "duckdb/parser/expression/function_expression.hpp"
7+
#include "duckdb/catalog/catalog.hpp"
28

39
using namespace std;
410

@@ -14,6 +20,22 @@ void BuiltinFunctions::RegisterSQLiteFunctions() {
1420
SQLType::VARCHAR, SQLType(SQLTypeId::BOOLEAN)},
1521
{"cid", "name", "type", "notnull", "dflt_value", "pk"}, pragma_table_info_init,
1622
pragma_table_info, nullptr));
23+
24+
CreateViewInfo info;
25+
info.schema = DEFAULT_SCHEMA;
26+
info.view_name = "sqlite_master";
27+
info.replace = true;
28+
29+
auto select = make_unique<SelectNode>();
30+
select->select_list.push_back(make_unique<StarExpression>());
31+
vector<unique_ptr<ParsedExpression>> children;
32+
33+
auto function = make_unique<FunctionExpression>(DEFAULT_SCHEMA, "sqlite_master", children);
34+
auto function_expr = make_unique<TableFunctionRef>();
35+
function_expr->function = move(function);
36+
select->from_table = move(function_expr);
37+
info.query = move(select);
38+
// catalog.CreateView(transaction, &info);
1739
}
1840

1941
} // namespace duckdb

src/main/client_context.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ unique_ptr<DataChunk> ClientContext::Fetch() {
8181
if (is_invalidated) {
8282
// ClientContext is invalidated: database has been closed
8383
open_result->error = "Database that this connection belongs to has been closed!";
84+
open_result->success = false;
8485
return nullptr;
8586
}
8687
try {

third_party/imdb/include/imdb_constants.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const int IMDB_QUERIES_COUNT = 113;
1+
const int IMDB_QUERIES_COUNT = 114;
22
const char *IMDB_QUERIES[] = {
33
/* 01a.sql */ "SELECT MIN(mc.note) AS production_note,\n MIN(t.title) AS movie_title,\n MIN(t.production_year) AS movie_year\nFROM company_type AS ct,\n info_type AS it,\n movie_companies AS mc,\n movie_info_idx AS mi_idx,\n title AS t\nWHERE ct.kind = 'production companies'\n AND it.info = 'top 250 rank'\n AND mc.note NOT LIKE '%(as Metro-Goldwyn-Mayer Pictures)%'\n AND (mc.note LIKE '%(co-production)%'\n OR mc.note LIKE '%(presents)%')\n AND ct.id = mc.company_type_id\n AND t.id = mc.movie_id\n AND t.id = mi_idx.movie_id\n AND mc.movie_id = mi_idx.movie_id\n AND it.id = mi_idx.info_type_id;\n\n",
44
/* 01b.sql */ "SELECT MIN(mc.note) AS production_note,\n MIN(t.title) AS movie_title,\n MIN(t.production_year) AS movie_year\nFROM company_type AS ct,\n info_type AS it,\n movie_companies AS mc,\n movie_info_idx AS mi_idx,\n title AS t\nWHERE ct.kind = 'production companies'\n AND it.info = 'bottom 10 rank'\n AND mc.note NOT LIKE '%(as Metro-Goldwyn-Mayer Pictures)%'\n AND t.production_year BETWEEN 2005 AND 2010\n AND ct.id = mc.company_type_id\n AND t.id = mc.movie_id\n AND t.id = mi_idx.movie_id\n AND mc.movie_id = mi_idx.movie_id\n AND it.id = mi_idx.info_type_id;\n\n",
@@ -112,7 +112,8 @@ const char *IMDB_QUERIES[] = {
112112
/* 32b.sql */ "SELECT MIN(lt.link) AS link_type,\n MIN(t1.title) AS first_movie,\n MIN(t2.title) AS second_movie\nFROM keyword AS k,\n link_type AS lt,\n movie_keyword AS mk,\n movie_link AS ml,\n title AS t1,\n title AS t2\nWHERE k.keyword ='character-name-in-title'\n AND mk.keyword_id = k.id\n AND t1.id = mk.movie_id\n AND ml.movie_id = t1.id\n AND ml.linked_movie_id = t2.id\n AND lt.id = ml.link_type_id\n AND mk.movie_id = t1.id;\n\n",
113113
/* 33a.sql */ "SELECT MIN(cn1.name) AS first_company,\n MIN(cn2.name) AS second_company,\n MIN(mi_idx1.info) AS first_rating,\n MIN(mi_idx2.info) AS second_rating,\n MIN(t1.title) AS first_movie,\n MIN(t2.title) AS second_movie\nFROM company_name AS cn1,\n company_name AS cn2,\n info_type AS it1,\n info_type AS it2,\n kind_type AS kt1,\n kind_type AS kt2,\n link_type AS lt,\n movie_companies AS mc1,\n movie_companies AS mc2,\n movie_info_idx AS mi_idx1,\n movie_info_idx AS mi_idx2,\n movie_link AS ml,\n title AS t1,\n title AS t2\nWHERE cn1.country_code = '[us]'\n AND it1.info = 'rating'\n AND it2.info = 'rating'\n AND kt1.kind IN ('tv series')\n AND kt2.kind IN ('tv series')\n AND lt.link IN ('sequel',\n 'follows',\n 'followed by')\n AND mi_idx2.info < '3.0'\n AND t2.production_year BETWEEN 2005 AND 2008\n AND lt.id = ml.link_type_id\n AND t1.id = ml.movie_id\n AND t2.id = ml.linked_movie_id\n AND it1.id = mi_idx1.info_type_id\n AND t1.id = mi_idx1.movie_id\n AND kt1.id = t1.kind_id\n AND cn1.id = mc1.company_id\n AND t1.id = mc1.movie_id\n AND ml.movie_id = mi_idx1.movie_id\n AND ml.movie_id = mc1.movie_id\n AND mi_idx1.movie_id = mc1.movie_id\n AND it2.id = mi_idx2.info_type_id\n AND t2.id = mi_idx2.movie_id\n AND kt2.id = t2.kind_id\n AND cn2.id = mc2.company_id\n AND t2.id = mc2.movie_id\n AND ml.linked_movie_id = mi_idx2.movie_id\n AND ml.linked_movie_id = mc2.movie_id\n AND mi_idx2.movie_id = mc2.movie_id;\n\n",
114114
/* 33b.sql */ "SELECT MIN(cn1.name) AS first_company,\n MIN(cn2.name) AS second_company,\n MIN(mi_idx1.info) AS first_rating,\n MIN(mi_idx2.info) AS second_rating,\n MIN(t1.title) AS first_movie,\n MIN(t2.title) AS second_movie\nFROM company_name AS cn1,\n company_name AS cn2,\n info_type AS it1,\n info_type AS it2,\n kind_type AS kt1,\n kind_type AS kt2,\n link_type AS lt,\n movie_companies AS mc1,\n movie_companies AS mc2,\n movie_info_idx AS mi_idx1,\n movie_info_idx AS mi_idx2,\n movie_link AS ml,\n title AS t1,\n title AS t2\nWHERE cn1.country_code = '[nl]'\n AND it1.info = 'rating'\n AND it2.info = 'rating'\n AND kt1.kind IN ('tv series')\n AND kt2.kind IN ('tv series')\n AND lt.link LIKE '%follow%'\n AND mi_idx2.info < '3.0'\n AND t2.production_year = 2007\n AND lt.id = ml.link_type_id\n AND t1.id = ml.movie_id\n AND t2.id = ml.linked_movie_id\n AND it1.id = mi_idx1.info_type_id\n AND t1.id = mi_idx1.movie_id\n AND kt1.id = t1.kind_id\n AND cn1.id = mc1.company_id\n AND t1.id = mc1.movie_id\n AND ml.movie_id = mi_idx1.movie_id\n AND ml.movie_id = mc1.movie_id\n AND mi_idx1.movie_id = mc1.movie_id\n AND it2.id = mi_idx2.info_type_id\n AND t2.id = mi_idx2.movie_id\n AND kt2.id = t2.kind_id\n AND cn2.id = mc2.company_id\n AND t2.id = mc2.movie_id\n AND ml.linked_movie_id = mi_idx2.movie_id\n AND ml.linked_movie_id = mc2.movie_id\n AND mi_idx2.movie_id = mc2.movie_id;\n\n",
115-
/* 33c.sql */ "SELECT MIN(cn1.name) AS first_company,\n MIN(cn2.name) AS second_company,\n MIN(mi_idx1.info) AS first_rating,\n MIN(mi_idx2.info) AS second_rating,\n MIN(t1.title) AS first_movie,\n MIN(t2.title) AS second_movie\nFROM company_name AS cn1,\n company_name AS cn2,\n info_type AS it1,\n info_type AS it2,\n kind_type AS kt1,\n kind_type AS kt2,\n link_type AS lt,\n movie_companies AS mc1,\n movie_companies AS mc2,\n movie_info_idx AS mi_idx1,\n movie_info_idx AS mi_idx2,\n movie_link AS ml,\n title AS t1,\n title AS t2\nWHERE cn1.country_code != '[us]'\n AND it1.info = 'rating'\n AND it2.info = 'rating'\n AND kt1.kind IN ('tv series',\n 'episode')\n AND kt2.kind IN ('tv series',\n 'episode')\n AND lt.link IN ('sequel',\n 'follows',\n 'followed by')\n AND mi_idx2.info < '3.5'\n AND t2.production_year BETWEEN 2000 AND 2010\n AND lt.id = ml.link_type_id\n AND t1.id = ml.movie_id\n AND t2.id = ml.linked_movie_id\n AND it1.id = mi_idx1.info_type_id\n AND t1.id = mi_idx1.movie_id\n AND kt1.id = t1.kind_id\n AND cn1.id = mc1.company_id\n AND t1.id = mc1.movie_id\n AND ml.movie_id = mi_idx1.movie_id\n AND ml.movie_id = mc1.movie_id\n AND mi_idx1.movie_id = mc1.movie_id\n AND it2.id = mi_idx2.info_type_id\n AND t2.id = mi_idx2.movie_id\n AND kt2.id = t2.kind_id\n AND cn2.id = mc2.company_id\n AND t2.id = mc2.movie_id\n AND ml.linked_movie_id = mi_idx2.movie_id\n AND ml.linked_movie_id = mc2.movie_id\n AND mi_idx2.movie_id = mc2.movie_id;\n\n"
115+
/* 33c.sql */ "SELECT MIN(cn1.name) AS first_company,\n MIN(cn2.name) AS second_company,\n MIN(mi_idx1.info) AS first_rating,\n MIN(mi_idx2.info) AS second_rating,\n MIN(t1.title) AS first_movie,\n MIN(t2.title) AS second_movie\nFROM company_name AS cn1,\n company_name AS cn2,\n info_type AS it1,\n info_type AS it2,\n kind_type AS kt1,\n kind_type AS kt2,\n link_type AS lt,\n movie_companies AS mc1,\n movie_companies AS mc2,\n movie_info_idx AS mi_idx1,\n movie_info_idx AS mi_idx2,\n movie_link AS ml,\n title AS t1,\n title AS t2\nWHERE cn1.country_code != '[us]'\n AND it1.info = 'rating'\n AND it2.info = 'rating'\n AND kt1.kind IN ('tv series',\n 'episode')\n AND kt2.kind IN ('tv series',\n 'episode')\n AND lt.link IN ('sequel',\n 'follows',\n 'followed by')\n AND mi_idx2.info < '3.5'\n AND t2.production_year BETWEEN 2000 AND 2010\n AND lt.id = ml.link_type_id\n AND t1.id = ml.movie_id\n AND t2.id = ml.linked_movie_id\n AND it1.id = mi_idx1.info_type_id\n AND t1.id = mi_idx1.movie_id\n AND kt1.id = t1.kind_id\n AND cn1.id = mc1.company_id\n AND t1.id = mc1.movie_id\n AND ml.movie_id = mi_idx1.movie_id\n AND ml.movie_id = mc1.movie_id\n AND mi_idx1.movie_id = mc1.movie_id\n AND it2.id = mi_idx2.info_type_id\n AND t2.id = mi_idx2.movie_id\n AND kt2.id = t2.kind_id\n AND cn2.id = mc2.company_id\n AND t2.id = mc2.movie_id\n AND ml.linked_movie_id = mi_idx2.movie_id\n AND ml.linked_movie_id = mc2.movie_id\n AND mi_idx2.movie_id = mc2.movie_id;\n\n",
116+
/* Moerkotte Special */ "select '(29a.sql (joincard (relset cc ci mc)', sum(cc.cnt * ci.cnt * mc.cnt), '))'\nfrom\n (select movie_id, count(*) as cnt from complete_cast group by movie_id) as cc,\n (select movie_id, count(*) as cnt from cast_info group by movie_id) as ci,\n (select movie_id, count(*) as cnt from movie_companies group by movie_id) as mc\nwhere mc.movie_id = ci.movie_id and\n mc.movie_id = cc.movie_id and\n ci.movie_id = cc.movie_id;\n"
116117
};
117118

118119

third_party/libpg_query/grammar/statements/select.y

+8
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,14 @@ a_expr: c_expr { $$ = $1; }
17521752
n->location = @2;
17531753
$$ = (PGNode *)n;
17541754
}
1755+
| a_expr NOT NULL_P
1756+
{
1757+
PGNullTest *n = makeNode(PGNullTest);
1758+
n->arg = (PGExpr *) $1;
1759+
n->nulltesttype = IS_NOT_NULL;
1760+
n->location = @2;
1761+
$$ = (PGNode *)n;
1762+
}
17551763
| a_expr NOTNULL
17561764
{
17571765
PGNullTest *n = makeNode(PGNullTest);

0 commit comments

Comments
 (0)