Skip to content

Commit

Permalink
Align extension to DuckDB 1.1.1 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Monahan committed Sep 26, 2024
1 parent 7fdc101 commit befaef4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 243 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
project(${TARGET_NAME})
include_directories(src/include)

set(EXTENSION_SOURCES src/dynamic_sql_examples_extension.cpp src/default_table_functions.cpp)
set(EXTENSION_SOURCES src/dynamic_sql_examples_extension.cpp)

build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
Expand Down
148 changes: 0 additions & 148 deletions src/default_table_functions.cpp

This file was deleted.

12 changes: 6 additions & 6 deletions src/dynamic_sql_examples_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
// OpenSSL linked through vcpkg
#include <openssl/opensslv.h>

#include "default_functions.hpp"
#include "default_table_functions.hpp"
#include "duckdb/catalog/default/default_functions.hpp"
#include "duckdb/catalog/default/default_table_functions.hpp"

namespace duckdb {

// To add a new scalar SQL macro, add a new macro to this array!
// Copy and paste the top item in the array into the
// second-to-last position and make some modifications.
// (essentially, leave the last entry in the array as {nullptr, nullptr, {nullptr}, nullptr})
// (essentially, leave the last entry in the array as {nullptr, nullptr, {nullptr}, {{nullptr, nullptr}}, nullptr})

// Keep the DEFAULT_SCHEMA (no change needed)
// Replace "times_two" with a name for your macro
// If your function has parameters, add their names in quotes inside of the {}, with a nullptr at the end
// If you do not have parameters, simplify to {nullptr}
// Add the text of your SQL macro as a raw string with the format R"( select 42 )"
static DefaultMacro dynamic_sql_examples_macros[] = {
{DEFAULT_SCHEMA, "times_two", {"x", nullptr}, R"(x*2)"},
{nullptr, nullptr, {nullptr}, nullptr}};
{DEFAULT_SCHEMA, "default_to_times_two", {"x", nullptr}, {{"multiplier", "2"}, {nullptr, nullptr}}, R"( x * multiplier )"},
{nullptr, nullptr, {nullptr}, {{nullptr, nullptr}}, nullptr}};


// To add a new table SQL macro, add a new macro to this array!
Expand All @@ -47,7 +47,7 @@ static DefaultMacro dynamic_sql_examples_macros[] = {

// clang-format off
static const DefaultTableMacro dynamic_sql_examples_table_macros[] = {
{DEFAULT_SCHEMA, "times_two_table", {"x", nullptr}, {{"two", "2"}, {nullptr, nullptr}}, R"(SELECT x * two as output_column;)"},
{DEFAULT_SCHEMA, "default_to_times_two_table", {"x", nullptr}, {{"multiplier", "2"}, {nullptr, nullptr}}, R"( SELECT x * multiplier as output_column; )"},
{nullptr, nullptr, {nullptr}, {{nullptr, nullptr}}, nullptr}
};
// clang-format on
Expand Down
41 changes: 0 additions & 41 deletions src/include/default_functions.hpp

This file was deleted.

47 changes: 0 additions & 47 deletions src/include/default_table_functions.hpp

This file was deleted.

13 changes: 13 additions & 0 deletions test/sql/dynamic_sql_examples.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ Catalog Error: Scalar Function with name dynamic_sql_examples does not exist!
require dynamic_sql_examples

# Confirm the extension works

# Test scalar macro overriding the default
query I
SELECT default_to_times_two(4, multiplier:=3);
----
12

# Test table macro overriding the default
query I
SELECT * FROM default_to_times_two_table(5, multiplier:=3);
----
15

query I
SELECT dynamic_sql_examples('Sam');
----
Expand Down

0 comments on commit befaef4

Please sign in to comment.