Skip to content

Commit

Permalink
rename extension to chsql
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 9, 2024
1 parent c192ab5 commit f5b430a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
with:
duckdb_version: v1.0.0
extension_name: dynamic_sql_clickhouse
extension_name: chsql

duckdb-stable-deploy:
name: Deploy extension binaries
Expand All @@ -26,6 +26,6 @@ jobs:
secrets: inherit
with:
duckdb_version: v1.0.0
extension_name: dynamic_sql_clickhouse
extension_name: chsql
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
deploy_versioned: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)

# Set extension name here
set(TARGET_NAME dynamic_sql_clickhouse)
set(TARGET_NAME chsql)

# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
Expand All @@ -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_clickhouse_extension.cpp src/default_table_functions.cpp)
set(EXTENSION_SOURCES src/chsql_extension.cpp src/default_table_functions.cpp)

build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Configuration of extension
EXT_NAME=dynamic_sql_clickhouse
EXT_NAME=chsql
EXT_CONFIG=${PROJ_DIR}extension_config.cmake

# Include the Makefile from extension-ci-tools
Expand Down
2 changes: 1 addition & 1 deletion extension_config.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is included by DuckDB's build system. It specifies which extension to load

# Extension from this repo
duckdb_extension_load(dynamic_sql_clickhouse
duckdb_extension_load(chsql
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}
LOAD_TESTS
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define DUCKDB_EXTENSION_MAIN

#include "dynamic_sql_clickhouse_extension.hpp"
#include "chsql_extension.hpp"
#include "duckdb.hpp"
#include "duckdb/common/exception.hpp"
#include "duckdb/common/string_util.hpp"
Expand Down Expand Up @@ -28,7 +28,7 @@ namespace duckdb {
// Add the text of your SQL macro as a raw string with the format R"( select 42 )"


static DefaultMacro dynamic_sql_clickhouse_macros[] = {
static DefaultMacro chsql_macros[] = {
{DEFAULT_SCHEMA, "times_two", {"x", nullptr}, R"(x*2)"},
{DEFAULT_SCHEMA, "toString", {"x", nullptr}, R"(CAST(x AS VARCHAR))"},
{DEFAULT_SCHEMA, "toInt8", {"x", nullptr}, R"(CAST(x AS INT8))"},
Expand Down Expand Up @@ -83,64 +83,64 @@ static DefaultMacro dynamic_sql_clickhouse_macros[] = {
// Add the text of your SQL macro as a raw string with the format R"( select 42; )"

// clang-format off
static const DefaultTableMacro dynamic_sql_clickhouse_table_macros[] = {
static const DefaultTableMacro chsql_table_macros[] = {
{DEFAULT_SCHEMA, "times_two_table", {"x", nullptr}, {{"two", "2"}, {nullptr, nullptr}}, R"(SELECT x * two as output_column;)"},
{nullptr, nullptr, {nullptr}, {{nullptr, nullptr}}, nullptr}
};
// clang-format on

inline void DynamicSqlClickhouseScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
inline void ChSqlScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
auto &name_vector = args.data[0];
UnaryExecutor::Execute<string_t, string_t>(
name_vector, result, args.size(),
[&](string_t name) {
return StringVector::AddString(result, "DynamicSqlClickhouse "+name.GetString()+" 🐥");;
return StringVector::AddString(result, "ChSql "+name.GetString()+" 🐥");;
});
}

inline void DynamicSqlClickhouseOpenSSLVersionScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
inline void ChSqlOpenSSLVersionScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
auto &name_vector = args.data[0];
UnaryExecutor::Execute<string_t, string_t>(
name_vector, result, args.size(),
[&](string_t name) {
return StringVector::AddString(result, "DynamicSqlClickhouse " + name.GetString() +
return StringVector::AddString(result, "ChSql " + name.GetString() +
", my linked OpenSSL version is " +
OPENSSL_VERSION_TEXT );;
});
}

static void LoadInternal(DatabaseInstance &instance) {
// Register a scalar function
auto dynamic_sql_clickhouse_scalar_function = ScalarFunction("dynamic_sql_clickhouse", {LogicalType::VARCHAR}, LogicalType::VARCHAR, DynamicSqlClickhouseScalarFun);
ExtensionUtil::RegisterFunction(instance, dynamic_sql_clickhouse_scalar_function);
auto chsql_scalar_function = ScalarFunction("chsql", {LogicalType::VARCHAR}, LogicalType::VARCHAR, ChSqlScalarFun);
ExtensionUtil::RegisterFunction(instance, chsql_scalar_function);

// Register another scalar function
auto dynamic_sql_clickhouse_openssl_version_scalar_function = ScalarFunction("dynamic_sql_clickhouse_openssl_version", {LogicalType::VARCHAR},
LogicalType::VARCHAR, DynamicSqlClickhouseOpenSSLVersionScalarFun);
ExtensionUtil::RegisterFunction(instance, dynamic_sql_clickhouse_openssl_version_scalar_function);
auto chsql_openssl_version_scalar_function = ScalarFunction("chsql_openssl_version", {LogicalType::VARCHAR},
LogicalType::VARCHAR, ChSqlOpenSSLVersionScalarFun);
ExtensionUtil::RegisterFunction(instance, chsql_openssl_version_scalar_function);

// Macros
for (idx_t index = 0; dynamic_sql_clickhouse_macros[index].name != nullptr; index++) {
auto info = DefaultFunctionGenerator::CreateInternalMacroInfo(dynamic_sql_clickhouse_macros[index]);
for (idx_t index = 0; chsql_macros[index].name != nullptr; index++) {
auto info = DefaultFunctionGenerator::CreateInternalMacroInfo(chsql_macros[index]);
ExtensionUtil::RegisterFunction(instance, *info);
}
// Table Macros
for (idx_t index = 0; dynamic_sql_clickhouse_table_macros[index].name != nullptr; index++) {
auto table_info = DefaultTableFunctionGenerator::CreateTableMacroInfo(dynamic_sql_clickhouse_table_macros[index]);
for (idx_t index = 0; chsql_table_macros[index].name != nullptr; index++) {
auto table_info = DefaultTableFunctionGenerator::CreateTableMacroInfo(chsql_table_macros[index]);
ExtensionUtil::RegisterFunction(instance, *table_info);
}
}

void DynamicSqlClickhouseExtension::Load(DuckDB &db) {
void ChsqlExtension::Load(DuckDB &db) {
LoadInternal(*db.instance);
}
std::string DynamicSqlClickhouseExtension::Name() {
return "dynamic_sql_clickhouse";
std::string ChsqlExtension::Name() {
return "chsql";
}

std::string DynamicSqlClickhouseExtension::Version() const {
#ifdef EXT_VERSION_DYNAMIC_SQL_CLICKHOUSE
return EXT_VERSION_DYNAMIC_SQL_CLICKHOUSE;
std::string ChsqlExtension::Version() const {
#ifdef EXT_VERSION_CHSQL
return EXT_VERSION_CHSQL;
#else
return "";
#endif
Expand All @@ -150,12 +150,12 @@ std::string DynamicSqlClickhouseExtension::Version() const {

extern "C" {

DUCKDB_EXTENSION_API void dynamic_sql_clickhouse_init(duckdb::DatabaseInstance &db) {
DUCKDB_EXTENSION_API void chsql_init(duckdb::DatabaseInstance &db) {
duckdb::DuckDB db_wrapper(db);
db_wrapper.LoadExtension<duckdb::DynamicSqlClickhouseExtension>();
db_wrapper.LoadExtension<duckdb::ChsqlExtension>();
}

DUCKDB_EXTENSION_API const char *dynamic_sql_clickhouse_version() {
DUCKDB_EXTENSION_API const char *chsql_version() {
return duckdb::DuckDB::LibraryVersion();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace duckdb {

class DynamicSqlClickhouseExtension : public Extension {
class ChsqlExtension : public Extension {
public:
void Load(DuckDB &db) override;
std::string Name() override;
Expand Down
20 changes: 10 additions & 10 deletions test/sql/dynamic_sql_clickhouse.test → test/sql/chsql.test
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# name: test/sql/dynamic_sql_clickhouse.test
# description: test dynamic_sql_clickhouse extension
# group: [dynamic_sql_clickhouse]
# name: test/sql/chsql.test
# description: test chsql extension
# group: [chsql]

# Before we load the extension, this will fail
statement error
SELECT dynamic_sql_clickhouse('Sam');
SELECT chsql('Sam');
----
Catalog Error: Scalar Function with name dynamic_sql_clickhouse does not exist!
Catalog Error: Scalar Function with name chsql does not exist!

# Require statement will ensure this test is run with this extension loaded
require dynamic_sql_clickhouse
require chsql

# Confirm the extension works
query I
SELECT dynamic_sql_clickhouse('Works');
SELECT chsql('Works');
----
DynamicSqlClickhouse Works 🐥
ChSql Works 🐥

query I
SELECT dynamic_sql_clickhouse_openssl_version('Hello');
SELECT chsql_openssl_version('Hello');
----
<REGEX>:.*DynamicSqlClickhouse Hello, my linked OpenSSL version is OpenSSL.*
<REGEX>:.*ChSql Hello, my linked OpenSSL version is OpenSSL.*

query I
SELECT toString('123')
Expand Down

0 comments on commit f5b430a

Please sign in to comment.