Skip to content

Commit

Permalink
Merge pull request #45 from Mause/dev-helpers
Browse files Browse the repository at this point in the history
Restores dev helpers
  • Loading branch information
Mause authored Jun 27, 2024
2 parents 7190b4f + 33870e2 commit 7730b47
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 94 deletions.
32 changes: 32 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
BasedOnStyle: LLVM
TabWidth: 4
IndentWidth: 4
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: false
---
UseTab: ForIndentation
DerivePointerAlignment: false
PointerAlignment: Right
AlignConsecutiveMacros: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AlignAfterOpenBracket: Align
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
IncludeBlocks: Regroup
Language: Cpp
AccessModifierOffset: -4
---
Language: Java
SpaceAfterCStyleCast: true
---
11 changes: 11 additions & 0 deletions .github/workflows/Java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ env:
OVERRIDE_GIT_DESCRIBE: ${{ inputs.override_git_describe }}

jobs:
format_check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.git_ref }}

- run: make format-check

java-linux-amd64:
name: Java Linux (amd64)
runs-on: ubuntu-latest
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ CP=$(JAR)$(SEP)$(TEST_JAR)
test:
java -cp $(CP) org.duckdb.TestDuckDBJDBC

debug:
mkdir -p build/debug
cd build/debug && cmake -DCMAKE_BUILD_TYPE=Debug $(GENERATOR) $(ARCH_OVERRIDE) ../.. && cmake --build . --config Debug

release:
mkdir -p build/release
cd build/release && cmake -DCMAKE_BUILD_TYPE=Release $(GENERATOR) $(ARCH_OVERRIDE) ../.. && cmake --build . --config Release

format:
python3 scripts/format.py

format-check:
python3 scripts/format.py --check

clean:
rm -rf build
rm -rf build
17 changes: 17 additions & 0 deletions scripts/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from subprocess import check_call
from os import scandir
from glob import glob
from argparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument('--check', action='store_true')
args = parser.parse_args()

template = ['clang-format', '-i']
if args.check:
template += ['--dry-run', '--Werror']

for name in ['src/jni/duckdb_java.cpp'] + glob('src/**/*.java', recursive=True):
print('Formatting', name)
check_call(template + [name])

39 changes: 18 additions & 21 deletions src/jni/duckdb_java.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "functions.hpp"
#include "duckdb.hpp"
#include "duckdb/catalog/catalog_search_path.hpp"
#include "duckdb/common/arrow/result_arrow_wrapper.hpp"
Expand All @@ -12,7 +11,7 @@
#include "duckdb/main/db_instance_cache.hpp"
#include "duckdb/main/extension_util.hpp"
#include "duckdb/parser/parsed_data/create_type_info.hpp"

#include "functions.hpp"

using namespace duckdb;
using namespace std;
Expand Down Expand Up @@ -604,17 +603,14 @@ Value ToValue(JNIEnv *env, jobject param, duckdb::shared_ptr<ClientContext> cont
} else if (env->IsInstanceOf(param, J_Long)) {
return (Value::BIGINT(env->CallLongMethod(param, J_Long_longValue)));
} else if (env->IsInstanceOf(param, J_TimestampTZ)) { // Check for subclass before superclass!
return (
Value::TIMESTAMPTZ((timestamp_t)env->CallLongMethod(param, J_TimestampTZ_getMicrosEpoch)));
return (Value::TIMESTAMPTZ((timestamp_t)env->CallLongMethod(param, J_TimestampTZ_getMicrosEpoch)));
} else if (env->IsInstanceOf(param, J_DuckDBDate)) {
return (
Value::DATE((date_t)env->CallLongMethod(param, J_DuckDBDate_getDaysSinceEpoch)));
return (Value::DATE((date_t)env->CallLongMethod(param, J_DuckDBDate_getDaysSinceEpoch)));

} else if (env->IsInstanceOf(param, J_DuckDBTime)) {
return (Value::TIME((dtime_t)env->CallLongMethod(param, J_Timestamp_getMicrosEpoch)));
} else if (env->IsInstanceOf(param, J_Timestamp)) {
return (
Value::TIMESTAMP((timestamp_t)env->CallLongMethod(param, J_Timestamp_getMicrosEpoch)));
return (Value::TIMESTAMP((timestamp_t)env->CallLongMethod(param, J_Timestamp_getMicrosEpoch)));
} else if (env->IsInstanceOf(param, J_Float)) {
return (Value::FLOAT(env->CallFloatMethod(param, J_Float_floatValue)));
} else if (env->IsInstanceOf(param, J_Double)) {
Expand Down Expand Up @@ -648,7 +644,8 @@ Value ToValue(JNIEnv *env, jobject param, duckdb::shared_ptr<ClientContext> cont
D_ASSERT(key);
D_ASSERT(value);

entries.push_back(Value::STRUCT({{"key", ToValue(env, key, context)}, {"value", ToValue(env, value, context)}}));
entries.push_back(
Value::STRUCT({{"key", ToValue(env, key, context)}, {"value", ToValue(env, value, context)}}));
}

return (Value::MAP(ListType::GetChildType(type), entries));
Expand Down Expand Up @@ -1240,18 +1237,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;
}
auto connection = get_connection(env, conn_buf);
if (!connection) {
return;
}

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);
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);

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);
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);
}
2 changes: 1 addition & 1 deletion src/main/java/org/duckdb/DuckDBAppender.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.duckdb;

import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.math.BigDecimal;
import org.duckdb.DuckDBTimestamp;

public class DuckDBAppender implements AutoCloseable {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/duckdb/DuckDBArray.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.duckdb;

import static org.duckdb.DuckDBResultSetMetaData.type_to_int;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Map;

import static org.duckdb.DuckDBResultSetMetaData.type_to_int;

public class DuckDBArray implements Array {
private final Object[] array;
private final DuckDBVector vector;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/duckdb/DuckDBConnection.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.duckdb;

import org.duckdb.user.DuckDBMap;
import org.duckdb.user.DuckDBUserArray;
import org.duckdb.user.DuckDBUserStruct;

import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
Expand All @@ -27,6 +23,9 @@
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import org.duckdb.user.DuckDBMap;
import org.duckdb.user.DuckDBUserArray;
import org.duckdb.user.DuckDBUserStruct;

public final class DuckDBConnection implements java.sql.Connection {

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/duckdb/DuckDBDatabaseMetaData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.duckdb;

import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;
import static java.lang.System.lineSeparator;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
Expand All @@ -15,8 +14,8 @@
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

import static java.lang.System.lineSeparator;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;

public class DuckDBDatabaseMetaData implements DatabaseMetaData {
DuckDBConnection conn;
Expand Down Expand Up @@ -825,7 +824,8 @@ public ResultSet getColumns(String catalogPattern, String schemaPattern, String
+ "table_catalog AS 'TABLE_CAT', "
+ "table_schema AS 'TABLE_SCHEM', "
+ "table_name AS 'TABLE_NAME', "
+ "column_name as 'COLUMN_NAME', " + makeDataMap("regexp_replace(c.data_type, '\\(.*\\)', '')", "DATA_TYPE") + ", "
+ "column_name as 'COLUMN_NAME', " +
makeDataMap("regexp_replace(c.data_type, '\\(.*\\)', '')", "DATA_TYPE") + ", "
+ "c.data_type AS 'TYPE_NAME', "
+ "NULL AS 'COLUMN_SIZE', NULL AS 'BUFFER_LENGTH', "
+ "numeric_precision AS 'DECIMAL_DIGITS', "
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/duckdb/DuckDBNative.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.file.Files;
Expand All @@ -11,7 +12,6 @@
import java.nio.file.StandardCopyOption;
import java.sql.SQLException;
import java.util.Properties;
import java.math.BigDecimal;

class DuckDBNative {
static {
Expand Down Expand Up @@ -49,8 +49,7 @@ class DuckDBNative {
Path lib_file = Files.createTempFile("libduckdb_java", ".so");
URL lib_res = DuckDBNative.class.getResource(lib_res_name);
if (lib_res == null) {
System.load(
Paths.get("../../build/release", lib_res_name).normalize().toAbsolutePath().toString());
System.load(Paths.get("build/debug", lib_res_name).normalize().toAbsolutePath().toString());
} else {
try (final InputStream lib_res_input_stream = lib_res.openStream()) {
Files.copy(lib_res_input_stream, lib_file, StandardCopyOption.REPLACE_EXISTING);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/org/duckdb/DuckDBPreparedStatement.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.duckdb;

import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
Expand All @@ -28,15 +28,14 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;

import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Logger;

public class DuckDBPreparedStatement implements PreparedStatement {
private static Logger logger = Logger.getLogger(DuckDBPreparedStatement.class.getName());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/duckdb/DuckDBStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.sql.SQLException;
import java.sql.Struct;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;

public class DuckDBStruct implements Struct {
private final Object[] attributes;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/duckdb/DuckDBTimestamp.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.duckdb;

import java.sql.Timestamp;
import java.sql.Time;
import java.sql.Date;
import java.time.ZoneOffset;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;

public class DuckDBTimestamp {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/duckdb/DuckDBVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.util.Map;
import java.util.HashMap;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -292,7 +292,7 @@ byte[] getBytes(int idx) throws SQLException {
if (isType(DuckDBColumnType.BLOB)) {
ByteBuffer bb = (ByteBuffer) varlen_data[idx];
bb.position(0);
byte [] bytes = new byte[bb.remaining()];
byte[] bytes = new byte[bb.remaining()];
bb.get(bytes);
return bytes;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/duckdb/JdbcUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.duckdb;

import java.sql.SQLException;
import java.io.InputStream;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

final class JdbcUtils {

Expand Down
Loading

0 comments on commit 7730b47

Please sign in to comment.