Skip to content

Commit

Permalink
updating type registration for test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Mühleisen committed May 22, 2024
1 parent 391c899 commit 493e925
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions src/jni/duckdb_java.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#include "functions.hpp"
#include "duckdb.hpp"
#include "duckdb/main/client_context.hpp"
#include "duckdb/common/shared_ptr.hpp"
#include "duckdb/main/client_data.hpp"
#include "duckdb/catalog/catalog_search_path.hpp"
#include "duckdb/main/appender.hpp"
#include "duckdb/common/operator/cast_operators.hpp"
#include "duckdb/main/db_instance_cache.hpp"
#include "duckdb/common/arrow/result_arrow_wrapper.hpp"
#include "duckdb/common/operator/cast_operators.hpp"
#include "duckdb/common/shared_ptr.hpp"
#include "duckdb/function/table/arrow.hpp"
#include "duckdb/main/appender.hpp"
#include "duckdb/main/client_context.hpp"
#include "duckdb/main/client_data.hpp"
#include "duckdb/main/database_manager.hpp"
#include "duckdb/main/db_instance_cache.hpp"
#include "duckdb/main/extension_util.hpp"
#include "duckdb/parser/parsed_data/create_type_info.hpp"


using namespace duckdb;
using namespace std;

Expand Down Expand Up @@ -1152,27 +1154,18 @@ void _duckdb_jdbc_arrow_register(JNIEnv *env, jclass, jobject conn_ref_buf, jlon

void _duckdb_jdbc_create_extension_type(JNIEnv *env, jclass, jobject conn_buf) {

auto connection = get_connection(env, conn_buf);
if (!connection) {
return;
}

connection->BeginTransaction();

child_list_t<LogicalType> children = {{"hello", LogicalType::VARCHAR}, {"world", LogicalType::VARCHAR}};
auto id = LogicalType::STRUCT(children);
auto type_name = "test_type";
id.SetAlias(type_name);
CreateTypeInfo info(type_name, id);

auto &catalog_name = DatabaseManager::GetDefaultDatabase(*connection->context);
auto &catalog = Catalog::GetCatalog(*connection->context, catalog_name);
catalog.CreateType(*connection->context, info);
auto connection = get_connection(env, conn_buf);
if (!connection) {
return;
}

LogicalType byte_test_type_type = LogicalTypeId::BLOB;
byte_test_type_type.SetAlias("byte_test_type");
CreateTypeInfo byte_test_type("byte_test_type", byte_test_type_type);
catalog.CreateType(*connection->context, byte_test_type);
auto &db_instance = DatabaseInstance::GetDatabase(*connection->context);
child_list_t<LogicalType> children = {{"hello", LogicalType::VARCHAR}, {"world", LogicalType::VARCHAR}};
auto hello_world_type = LogicalType::STRUCT(children);
hello_world_type.SetAlias("test_type");
ExtensionUtil::RegisterType(db_instance, "test_type", hello_world_type);

connection->Commit();
LogicalType byte_test_type_type = LogicalTypeId::BLOB;
byte_test_type_type.SetAlias("byte_test_type");
ExtensionUtil::RegisterType(db_instance, "byte_test_type", byte_test_type_type);
}

0 comments on commit 493e925

Please sign in to comment.