Skip to content

Commit 37b74b0

Browse files
committed
get access to user input (sql)
1 parent 8b3ed92 commit 37b74b0

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/parse_tables_extension.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ struct ParseTablesState : public GlobalTableFunctionState {
1515
idx_t row = 0;
1616
};
1717

18+
struct ParseTablesBindData : public TableFunctionData {
19+
string sql;
20+
};
21+
1822
struct TableRefResult {
1923
string schema;
2024
string table;
@@ -23,13 +27,25 @@ struct TableRefResult {
2327

2428
// BIND function: runs during query planning to decide output schema
2529
static unique_ptr<FunctionData> Bind(ClientContext &context,
26-
TableFunctionBindInput &input,
27-
vector<LogicalType> &return_types,
28-
vector<string> &names) {
30+
TableFunctionBindInput &input,
31+
vector<LogicalType> &return_types,
32+
vector<string> &names) {
33+
34+
string sql_input = StringValue::Get(input.inputs[0]);
35+
std::cout << "sql_input: " << sql_input << std::endl;
36+
37+
// always return the same columns:
38+
2939
return_types = {LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR};
3040
// schema name, table name, usage context (from, join, cte, etc)
3141
names = {"schema", "table", "context"};
32-
return nullptr;
42+
43+
// create a bind data object to hold the SQL input
44+
45+
auto result = make_uniq<ParseTablesBindData>();
46+
result->sql = sql_input;
47+
48+
return std::move(result);
3349
}
3450

3551
// INIT function: runs before table function execution
@@ -47,6 +63,10 @@ static void MyFunc(ClientContext &context,
4763

4864
std::cout << "row: " << state.row << std::endl;
4965

66+
auto &bind_data = (ParseTablesBindData &)*data.bind_data;
67+
68+
std::cout << "Executing for SQL: " << bind_data.sql << std::endl;
69+
5070
if (state.row >= 1) {
5171
return; // no more rows to produce
5272
}

0 commit comments

Comments
 (0)