duckdb 0.3.2-dev579.0 → 0.3.2-dev589.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb.cpp +96 -22
- package/src/duckdb.hpp +19 -2
package/package.json
CHANGED
package/src/duckdb.cpp
CHANGED
|
@@ -102046,6 +102046,25 @@ void ClientContext::TryBindRelation(Relation &relation, vector<ColumnDefinition>
|
|
|
102046
102046
|
});
|
|
102047
102047
|
}
|
|
102048
102048
|
|
|
102049
|
+
unordered_set<string> ClientContext::GetTableNames(const string &query) {
|
|
102050
|
+
auto lock = LockContext();
|
|
102051
|
+
|
|
102052
|
+
auto statements = ParseStatementsInternal(*lock, query);
|
|
102053
|
+
if (statements.size() != 1) {
|
|
102054
|
+
throw InvalidInputException("Expected a single statement");
|
|
102055
|
+
}
|
|
102056
|
+
|
|
102057
|
+
unordered_set<string> result;
|
|
102058
|
+
RunFunctionInTransactionInternal(*lock, [&]() {
|
|
102059
|
+
// bind the expressions
|
|
102060
|
+
auto binder = Binder::CreateBinder(*this);
|
|
102061
|
+
binder->SetBindingMode(BindingMode::EXTRACT_NAMES);
|
|
102062
|
+
binder->Bind(*statements[0]);
|
|
102063
|
+
result = binder->GetTableNames();
|
|
102064
|
+
});
|
|
102065
|
+
return result;
|
|
102066
|
+
}
|
|
102067
|
+
|
|
102049
102068
|
unique_ptr<QueryResult> ClientContext::Execute(const shared_ptr<Relation> &relation) {
|
|
102050
102069
|
auto lock = LockContext();
|
|
102051
102070
|
InitialCleanup(*lock);
|
|
@@ -103004,6 +103023,10 @@ shared_ptr<Relation> Connection::ReadCSV(const string &csv_file, const vector<st
|
|
|
103004
103023
|
return make_shared<ReadCSVRelation>(*context, csv_file, move(column_list));
|
|
103005
103024
|
}
|
|
103006
103025
|
|
|
103026
|
+
unordered_set<string> Connection::GetTableNames(const string &query) {
|
|
103027
|
+
return context->GetTableNames(query);
|
|
103028
|
+
}
|
|
103029
|
+
|
|
103007
103030
|
shared_ptr<Relation> Connection::RelationFromQuery(const string &query, const string &alias) {
|
|
103008
103031
|
return make_shared<QueryRelation>(*context, query, alias);
|
|
103009
103032
|
}
|
|
@@ -145427,6 +145450,7 @@ private:
|
|
|
145427
145450
|
|
|
145428
145451
|
|
|
145429
145452
|
|
|
145453
|
+
|
|
145430
145454
|
namespace duckdb {
|
|
145431
145455
|
|
|
145432
145456
|
unique_ptr<ParsedExpression> ExpressionBinder::QualifyColumnName(const string &column_name, string &error_message) {
|
|
@@ -145589,6 +145613,9 @@ unique_ptr<ParsedExpression> ExpressionBinder::QualifyColumnName(ColumnRefExpres
|
|
|
145589
145613
|
}
|
|
145590
145614
|
|
|
145591
145615
|
BindResult ExpressionBinder::BindExpression(ColumnRefExpression &colref_p, idx_t depth) {
|
|
145616
|
+
if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES) {
|
|
145617
|
+
return BindResult(make_unique<BoundConstantExpression>(Value(LogicalType::SQLNULL)));
|
|
145618
|
+
}
|
|
145592
145619
|
string error_message;
|
|
145593
145620
|
auto expr = QualifyColumnName(colref_p, error_message);
|
|
145594
145621
|
if (!expr) {
|
|
@@ -145850,6 +145877,10 @@ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, ScalarFu
|
|
|
145850
145877
|
if (!error.empty()) {
|
|
145851
145878
|
return BindResult(error);
|
|
145852
145879
|
}
|
|
145880
|
+
if (binder.GetBindingMode() == BindingMode::EXTRACT_NAMES) {
|
|
145881
|
+
return BindResult(make_unique<BoundConstantExpression>(Value(LogicalType::SQLNULL)));
|
|
145882
|
+
}
|
|
145883
|
+
|
|
145853
145884
|
// all children bound successfully
|
|
145854
145885
|
// extract the children and types
|
|
145855
145886
|
vector<unique_ptr<Expression>> children;
|
|
@@ -149981,6 +150012,29 @@ public:
|
|
|
149981
150012
|
|
|
149982
150013
|
|
|
149983
150014
|
|
|
150015
|
+
//===----------------------------------------------------------------------===//
|
|
150016
|
+
// DuckDB
|
|
150017
|
+
//
|
|
150018
|
+
// duckdb/planner/tableref/bound_dummytableref.hpp
|
|
150019
|
+
//
|
|
150020
|
+
//
|
|
150021
|
+
//===----------------------------------------------------------------------===//
|
|
150022
|
+
|
|
150023
|
+
|
|
150024
|
+
|
|
150025
|
+
|
|
150026
|
+
|
|
150027
|
+
namespace duckdb {
|
|
150028
|
+
|
|
150029
|
+
//! Represents a cross product
|
|
150030
|
+
class BoundEmptyTableRef : public BoundTableRef {
|
|
150031
|
+
public:
|
|
150032
|
+
explicit BoundEmptyTableRef(idx_t bind_index) : BoundTableRef(TableReferenceType::EMPTY), bind_index(bind_index) {
|
|
150033
|
+
}
|
|
150034
|
+
idx_t bind_index;
|
|
150035
|
+
};
|
|
150036
|
+
} // namespace duckdb
|
|
150037
|
+
|
|
149984
150038
|
|
|
149985
150039
|
namespace duckdb {
|
|
149986
150040
|
|
|
@@ -150044,6 +150098,19 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
|
|
|
150044
150098
|
return Bind(*replacement_function);
|
|
150045
150099
|
}
|
|
150046
150100
|
}
|
|
150101
|
+
// we still didn't find the table
|
|
150102
|
+
if (GetBindingMode() == BindingMode::EXTRACT_NAMES) {
|
|
150103
|
+
// if we are in EXTRACT_NAMES, we create a dummy table ref
|
|
150104
|
+
AddTableName(ref.table_name);
|
|
150105
|
+
|
|
150106
|
+
// add a bind context entry
|
|
150107
|
+
auto table_index = GenerateTableIndex();
|
|
150108
|
+
auto alias = ref.alias.empty() ? ref.table_name : ref.alias;
|
|
150109
|
+
vector<LogicalType> types {LogicalType::INTEGER};
|
|
150110
|
+
vector<string> names {"__dummy_col" + to_string(table_index)};
|
|
150111
|
+
bind_context.AddGenericBinding(table_index, alias, names, types);
|
|
150112
|
+
return make_unique_base<BoundTableRef, BoundEmptyTableRef>(table_index);
|
|
150113
|
+
}
|
|
150047
150114
|
// could not find an alternative: bind again to get the error
|
|
150048
150115
|
table_or_view = Catalog::GetCatalog(context).GetEntry(context, CatalogType::TABLE_ENTRY, ref.schema_name,
|
|
150049
150116
|
ref.table_name, false, error_context);
|
|
@@ -150126,28 +150193,6 @@ unique_ptr<BoundTableRef> Binder::Bind(CrossProductRef &ref) {
|
|
|
150126
150193
|
} // namespace duckdb
|
|
150127
150194
|
|
|
150128
150195
|
|
|
150129
|
-
//===----------------------------------------------------------------------===//
|
|
150130
|
-
// DuckDB
|
|
150131
|
-
//
|
|
150132
|
-
// duckdb/planner/tableref/bound_dummytableref.hpp
|
|
150133
|
-
//
|
|
150134
|
-
//
|
|
150135
|
-
//===----------------------------------------------------------------------===//
|
|
150136
|
-
|
|
150137
|
-
|
|
150138
|
-
|
|
150139
|
-
|
|
150140
|
-
|
|
150141
|
-
namespace duckdb {
|
|
150142
|
-
|
|
150143
|
-
//! Represents a cross product
|
|
150144
|
-
class BoundEmptyTableRef : public BoundTableRef {
|
|
150145
|
-
public:
|
|
150146
|
-
explicit BoundEmptyTableRef(idx_t bind_index) : BoundTableRef(TableReferenceType::EMPTY), bind_index(bind_index) {
|
|
150147
|
-
}
|
|
150148
|
-
idx_t bind_index;
|
|
150149
|
-
};
|
|
150150
|
-
} // namespace duckdb
|
|
150151
150196
|
|
|
150152
150197
|
|
|
150153
150198
|
namespace duckdb {
|
|
@@ -151406,6 +151451,35 @@ bool Binder::HasMatchingBinding(const string &schema_name, const string &table_n
|
|
|
151406
151451
|
return true;
|
|
151407
151452
|
}
|
|
151408
151453
|
|
|
151454
|
+
void Binder::SetBindingMode(BindingMode mode) {
|
|
151455
|
+
if (parent) {
|
|
151456
|
+
parent->SetBindingMode(mode);
|
|
151457
|
+
}
|
|
151458
|
+
this->mode = mode;
|
|
151459
|
+
}
|
|
151460
|
+
|
|
151461
|
+
BindingMode Binder::GetBindingMode() {
|
|
151462
|
+
if (parent) {
|
|
151463
|
+
return parent->GetBindingMode();
|
|
151464
|
+
}
|
|
151465
|
+
return mode;
|
|
151466
|
+
}
|
|
151467
|
+
|
|
151468
|
+
void Binder::AddTableName(string table_name) {
|
|
151469
|
+
if (parent) {
|
|
151470
|
+
parent->AddTableName(move(table_name));
|
|
151471
|
+
return;
|
|
151472
|
+
}
|
|
151473
|
+
table_names.insert(move(table_name));
|
|
151474
|
+
}
|
|
151475
|
+
|
|
151476
|
+
const unordered_set<string> &Binder::GetTableNames() {
|
|
151477
|
+
if (parent) {
|
|
151478
|
+
return parent->GetTableNames();
|
|
151479
|
+
}
|
|
151480
|
+
return table_names;
|
|
151481
|
+
}
|
|
151482
|
+
|
|
151409
151483
|
string Binder::FormatError(ParsedExpression &expr_context, const string &message) {
|
|
151410
151484
|
return FormatError(expr_context.query_location, message);
|
|
151411
151485
|
}
|
package/src/duckdb.hpp
CHANGED
|
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
10
10
|
|
|
11
11
|
#pragma once
|
|
12
12
|
#define DUCKDB_AMALGAMATION 1
|
|
13
|
-
#define DUCKDB_SOURCE_ID "
|
|
14
|
-
#define DUCKDB_VERSION "0.3.2-
|
|
13
|
+
#define DUCKDB_SOURCE_ID "43cae15ac"
|
|
14
|
+
#define DUCKDB_VERSION "0.3.2-dev589"
|
|
15
15
|
//===----------------------------------------------------------------------===//
|
|
16
16
|
// DuckDB
|
|
17
17
|
//
|
|
@@ -9621,6 +9621,9 @@ public:
|
|
|
9621
9621
|
DUCKDB_API void SetAutoCommit(bool auto_commit);
|
|
9622
9622
|
DUCKDB_API bool IsAutoCommit();
|
|
9623
9623
|
|
|
9624
|
+
//! Fetch a list of table names that are required for a given query
|
|
9625
|
+
DUCKDB_API unordered_set<string> GetTableNames(const string &query);
|
|
9626
|
+
|
|
9624
9627
|
template <typename TR, typename... Args>
|
|
9625
9628
|
void CreateScalarFunction(const string &name, TR (*udf_func)(Args...)) {
|
|
9626
9629
|
scalar_function_t function = UDFWrapper::CreateScalarFunction<TR, Args...>(name, udf_func);
|
|
@@ -14683,6 +14686,8 @@ struct BoundCreateTableInfo;
|
|
|
14683
14686
|
struct BoundCreateFunctionInfo;
|
|
14684
14687
|
struct CommonTableExpressionInfo;
|
|
14685
14688
|
|
|
14689
|
+
enum class BindingMode : uint8_t { STANDARD_BINDING, EXTRACT_NAMES };
|
|
14690
|
+
|
|
14686
14691
|
struct CorrelatedColumnInfo {
|
|
14687
14692
|
ColumnBinding binding;
|
|
14688
14693
|
LogicalType type;
|
|
@@ -14797,6 +14802,11 @@ public:
|
|
|
14797
14802
|
bool HasMatchingBinding(const string &schema_name, const string &table_name, const string &column_name,
|
|
14798
14803
|
string &error_message);
|
|
14799
14804
|
|
|
14805
|
+
void SetBindingMode(BindingMode mode);
|
|
14806
|
+
BindingMode GetBindingMode();
|
|
14807
|
+
void AddTableName(string table_name);
|
|
14808
|
+
const unordered_set<string> &GetTableNames();
|
|
14809
|
+
|
|
14800
14810
|
private:
|
|
14801
14811
|
//! The parent binder (if any)
|
|
14802
14812
|
shared_ptr<Binder> parent;
|
|
@@ -14814,6 +14824,10 @@ private:
|
|
|
14814
14824
|
bool can_contain_nulls = false;
|
|
14815
14825
|
//! The root statement of the query that is currently being parsed
|
|
14816
14826
|
SQLStatement *root_statement = nullptr;
|
|
14827
|
+
//! Binding mode
|
|
14828
|
+
BindingMode mode = BindingMode::STANDARD_BINDING;
|
|
14829
|
+
//! Table names extracted for BindingMode::EXTRACT_NAMES
|
|
14830
|
+
unordered_set<string> table_names;
|
|
14817
14831
|
|
|
14818
14832
|
private:
|
|
14819
14833
|
//! Bind the default values of the columns of a table
|
|
@@ -17025,6 +17039,9 @@ public:
|
|
|
17025
17039
|
//! Equivalent to CURRENT_SETTING(key) SQL function.
|
|
17026
17040
|
DUCKDB_API bool TryGetCurrentSetting(const std::string &key, Value &result);
|
|
17027
17041
|
|
|
17042
|
+
//! Fetch a list of table names that are required for a given query
|
|
17043
|
+
DUCKDB_API unordered_set<string> GetTableNames(const string &query);
|
|
17044
|
+
|
|
17028
17045
|
private:
|
|
17029
17046
|
//! Parse statements from a query
|
|
17030
17047
|
vector<unique_ptr<SQLStatement>> ParseStatementsInternal(ClientContextLock &lock, const string &query);
|