Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 157 additions & 35 deletions src/generated/generated_temporal_udfs.cpp

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/include/temporal/set_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ struct SetFunctions {
static void Dateset_to_tstzset(DataChunk &args, ExpressionState &state, Vector &result);
static void Tstzset_to_dateset(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_mem_size(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_hash(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_hash_extended(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_num_values(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_start_value(DataChunk &args, ExpressionState &state, Vector &result);
static void Set_end_value(DataChunk &args, ExpressionState &state, Vector &result);
Expand Down
2 changes: 0 additions & 2 deletions src/include/temporal/span_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ struct SpanFunctions {
// accessors
static void Span_lower(DataChunk &args, ExpressionState &state, Vector &result);
static void Span_upper(DataChunk &args, ExpressionState &state, Vector &result);
static void Span_hash(DataChunk &args, ExpressionState &state, Vector &result);
static void Span_hash_extended(DataChunk &args, ExpressionState &state, Vector &result);
static void Span_lower_inc(DataChunk &args, ExpressionState &state, Vector &result);
static void Span_upper_inc(DataChunk &args, ExpressionState &state, Vector &result);
static void Numspan_width(DataChunk &args, ExpressionState &state, Vector &result);
Expand Down
2 changes: 0 additions & 2 deletions src/include/temporal/spanset_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ struct SpansetFunctions{
static void Spanset_mem_size(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_lower(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_upper(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_hash(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_hash_extended(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_lower_inc(DataChunk &args, ExpressionState &state, Vector &result);
static void Spanset_upper_inc(DataChunk &args, ExpressionState &state, Vector &result);
static void Numspanset_width(DataChunk &args, ExpressionState &state, Vector &result);
Expand Down
9 changes: 2 additions & 7 deletions src/temporal/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,8 @@ void SetTypes::RegisterScalarFunctions(ExtensionLoader &loader) {
ScalarFunction("memSize",{set_type}, LogicalType::INTEGER, SetFunctions::Set_mem_size)
);

duckdb::RegisterSerializedScalarFunction(loader,
ScalarFunction("set_hash", {set_type}, LogicalType::UINTEGER, SetFunctions::Set_hash)
);

duckdb::RegisterSerializedScalarFunction(loader,
ScalarFunction("set_hash_extended", {set_type, LogicalType::BIGINT}, LogicalType::UBIGINT, SetFunctions::Set_hash_extended)
);
// hash(set_type) / hashExtended(set_type, UBIGINT) are generated from the
// catalog (meos_setspan_accessor) in generated_temporal_udfs.cpp.

// numValues / startValue / endValue on set types are generated from the
// catalog (meos_setspan_accessor) in generated_temporal_udfs.cpp.
Expand Down
32 changes: 0 additions & 32 deletions src/temporal/set_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,38 +541,6 @@ void SetFunctions::Set_mem_size(DataChunk &args, ExpressionState &state, Vector
});
}

// --- set_hash / set_hash_extended ---
void SetFunctions::Set_hash(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
UnaryExecutor::Execute<string_t, uint32_t>(
input, result, args.size(),
[&](string_t input_blob) -> uint32_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
Set *s = (Set*)malloc(size);
memcpy(s, data, size);
uint32_t h = set_hash(s);
free(s);
return h;
});
}

void SetFunctions::Set_hash_extended(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
auto &seed_vec = args.data[1];
BinaryExecutor::Execute<string_t, int64_t, uint64_t>(
input, seed_vec, result, args.size(),
[&](string_t input_blob, int64_t seed) -> uint64_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
Set *s = (Set*)malloc(size);
memcpy(s, data, size);
uint64_t h = set_hash_extended(s, (uint64_t)seed);
free(s);
return h;
});
}

// --- numValue ---
void SetFunctions::Set_num_values(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
Expand Down
4 changes: 2 additions & 2 deletions src/temporal/span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ void SpanTypes::RegisterScalarFunctions(ExtensionLoader &loader) {
duckdb::RegisterSerializedScalarFunction(loader, ScalarFunction("lowerInc",{span_type}, LogicalType::BOOLEAN, SpanFunctions::Span_lower_inc));
duckdb::RegisterSerializedScalarFunction(loader, ScalarFunction("upperInc",{span_type}, LogicalType::BOOLEAN, SpanFunctions::Span_upper_inc));

duckdb::RegisterSerializedScalarFunction(loader, ScalarFunction("span_hash", {span_type}, LogicalType::UINTEGER, SpanFunctions::Span_hash));
duckdb::RegisterSerializedScalarFunction(loader, ScalarFunction("span_hash_extended", {span_type, LogicalType::BIGINT}, LogicalType::UBIGINT, SpanFunctions::Span_hash_extended));
// hash(span_type) / hashExtended(span_type, UBIGINT) are generated from the
// catalog (meos_setspan_accessor) in generated_temporal_udfs.cpp.
}

// expand(intspan/bigintspan/floatspan, <numeric>) is generated from the catalog
Expand Down
31 changes: 0 additions & 31 deletions src/temporal/span_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,37 +861,6 @@ void SpanFunctions::Span_upper(DataChunk &args, ExpressionState &state, Vector &
}
}

void SpanFunctions::Span_hash(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
UnaryExecutor::Execute<string_t, uint32_t>(
input, result, args.size(),
[&](string_t input_blob) -> uint32_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
Span *s = (Span*)malloc(size);
memcpy(s, data, size);
uint32_t h = span_hash(s);
free(s);
return h;
});
}

void SpanFunctions::Span_hash_extended(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
auto &seed_vec = args.data[1];
BinaryExecutor::Execute<string_t, int64_t, uint64_t>(
input, seed_vec, result, args.size(),
[&](string_t input_blob, int64_t seed) -> uint64_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
Span *s = (Span*)malloc(size);
memcpy(s, data, size);
uint64_t h = span_hash_extended(s, (uint64_t)seed);
free(s);
return h;
});
}

void SpanFunctions::Span_lower_inc(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
auto span_type = SpanTypeMapping::GetMeosTypeFromAlias(input.GetType().ToString());
Expand Down
9 changes: 2 additions & 7 deletions src/temporal/spanset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,8 @@ void SpansetTypes::RegisterScalarFunctions(ExtensionLoader &loader) {
ScalarFunction("splitEachNspans", {spanset_type, LogicalType::INTEGER}, LogicalType::LIST(child_type), SpansetFunctions::Spanset_split_each_n_spans)
);

// Hash
duckdb::RegisterSerializedScalarFunction(loader,
ScalarFunction("spanset_hash", {spanset_type}, LogicalType::UINTEGER, SpansetFunctions::Spanset_hash)
);
duckdb::RegisterSerializedScalarFunction(loader,
ScalarFunction("spanset_hash_extended", {spanset_type, LogicalType::BIGINT}, LogicalType::UBIGINT, SpansetFunctions::Spanset_hash_extended)
);
// hash(spanset_type) / hashExtended(spanset_type, UBIGINT) are generated from
// the catalog (meos_setspan_accessor) in generated_temporal_udfs.cpp.

// comparison operators
duckdb::RegisterSerializedScalarFunction(loader,
Expand Down
33 changes: 0 additions & 33 deletions src/temporal/spanset_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,39 +742,6 @@ void SpansetFunctions::Spanset_upper(DataChunk &args, ExpressionState &state, Ve
}
}

// --- spanset_hash / spanset_hash_extended ---

void SpansetFunctions::Spanset_hash(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
UnaryExecutor::Execute<string_t, uint32_t>(
input, result, args.size(),
[&](string_t input_blob) -> uint32_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
SpanSet *s = (SpanSet*)malloc(size);
memcpy(s, data, size);
uint32_t h = spanset_hash(s);
free(s);
return h;
});
}

void SpansetFunctions::Spanset_hash_extended(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input = args.data[0];
auto &seed_vec = args.data[1];
BinaryExecutor::Execute<string_t, int64_t, uint64_t>(
input, seed_vec, result, args.size(),
[&](string_t input_blob, int64_t seed) -> uint64_t {
const uint8_t *data = (const uint8_t *)input_blob.GetData();
size_t size = input_blob.GetSize();
SpanSet *s = (SpanSet*)malloc(size);
memcpy(s, data, size);
uint64_t h = spanset_hash_extended(s, (uint64_t)seed);
free(s);
return h;
});
}

// --- lower_inc ---

void SpansetFunctions::Spanset_lower_inc(DataChunk &args, ExpressionState &state, Vector &result) {
Expand Down
24 changes: 13 additions & 11 deletions test/sql/parity/001_set.test
Original file line number Diff line number Diff line change
Expand Up @@ -483,49 +483,51 @@ SELECT tstzset '{2000-01-01}' >= tstzset '{2000-01-01, 2000-01-02, 2000-01-03}';
----
false

mode skip
# set_hash / set_hash_extended not registered. MEOS symbols:
# set_hash, set_hash_extended.
# hash / hashExtended over set types. hash (uint32 -> UINTEGER) and
# hashExtended (uint64 + seed -> UBIGINT); the extended form is generated
# from the catalog (meos_setspan_accessor) with the canonical bare name.
query I
SELECT set_hash(dateset '{2000-01-01,2000-01-02}') = set_hash(dateset '{2000-01-01,2000-01-02}');
SELECT hash(dateset '{2000-01-01,2000-01-02}') = hash(dateset '{2000-01-01,2000-01-02}');
----
true

query I
SELECT set_hash(dateset '{2000-01-01,2000-01-02}') <> set_hash(dateset '{2000-01-01,2000-01-02}');
SELECT hash(dateset '{2000-01-01,2000-01-02}') <> hash(dateset '{2000-01-01,2000-01-02}');
----
false

query I
SELECT set_hash(tstzset '{2000-01-01,2000-01-02}') = set_hash(tstzset '{2000-01-01,2000-01-02}');
SELECT hash(tstzset '{2000-01-01,2000-01-02}') = hash(tstzset '{2000-01-01,2000-01-02}');
----
true

query I
SELECT set_hash(tstzset '{2000-01-01,2000-01-02}') <> set_hash(tstzset '{2000-01-01,2000-01-02}');
SELECT hash(tstzset '{2000-01-01,2000-01-02}') <> hash(tstzset '{2000-01-01,2000-01-02}');
----
false

query I
SELECT set_hash_extended(dateset '{2000-01-01,2000-01-02}', 1) = set_hash_extended(dateset '{2000-01-01,2000-01-02}', 1);
SELECT hashExtended(dateset '{2000-01-01,2000-01-02}', 1) = hashExtended(dateset '{2000-01-01,2000-01-02}', 1);
----
true

query I
SELECT set_hash_extended(dateset '{2000-01-01,2000-01-02}', 1) <> set_hash_extended(dateset '{2000-01-01,2000-01-02}', 1);
SELECT hashExtended(dateset '{2000-01-01,2000-01-02}', 1) <> hashExtended(dateset '{2000-01-01,2000-01-02}', 1);
----
false

query I
SELECT set_hash_extended(tstzset '{2000-01-01,2000-01-02}', 1) = set_hash_extended(tstzset '{2000-01-01,2000-01-02}', 1);
SELECT hashExtended(tstzset '{2000-01-01,2000-01-02}', 1) = hashExtended(tstzset '{2000-01-01,2000-01-02}', 1);
----
true

query I
SELECT set_hash_extended(tstzset '{2000-01-01,2000-01-02}', 1) <> set_hash_extended(tstzset '{2000-01-01,2000-01-02}', 1);
SELECT hashExtended(tstzset '{2000-01-01,2000-01-02}', 1) <> hashExtended(tstzset '{2000-01-01,2000-01-02}', 1);
----
false

mode skip

# =============================================================================
# Transformations
# =============================================================================
Expand Down
8 changes: 4 additions & 4 deletions test/sql/parity/003_span.test
Original file line number Diff line number Diff line change
Expand Up @@ -299,22 +299,22 @@ SELECT ge(tstzspan '[2000-01-01,2000-01-01]', tstzspan '(2000-01-01,2000-01-02)'
false

query I
SELECT span_hash(tstzspan '[2000-01-01,2000-01-02]') = span_hash(tstzspan '[2000-01-01,2000-01-02]');
SELECT hash(tstzspan '[2000-01-01,2000-01-02]') = hash(tstzspan '[2000-01-01,2000-01-02]');
----
true

query I
SELECT span_hash(tstzspan '[2000-01-01,2000-01-02]') <> span_hash(tstzspan '[2000-01-02,2000-01-02]');
SELECT hash(tstzspan '[2000-01-01,2000-01-02]') <> hash(tstzspan '[2000-01-02,2000-01-02]');
----
true

query I
SELECT span_hash_extended(tstzspan '[2000-01-01,2000-01-02]', 1) = span_hash_extended(tstzspan '[2000-01-01,2000-01-02]', 1);
SELECT hashExtended(tstzspan '[2000-01-01,2000-01-02]', 1) = hashExtended(tstzspan '[2000-01-01,2000-01-02]', 1);
----
true

query I
SELECT span_hash_extended(tstzspan '[2000-01-01,2000-01-02]', 1) <> span_hash_extended(tstzspan '[2000-01-02,2000-01-02]', 1);
SELECT hashExtended(tstzspan '[2000-01-01,2000-01-02]', 1) <> hashExtended(tstzspan '[2000-01-02,2000-01-02]', 1);
----
true

Expand Down
4 changes: 2 additions & 2 deletions test/sql/parity/007_spanset.test
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@ SELECT intspanset '{[1,1]}' >= intspanset '{[1,2),[2,3),[3,4)}';
false

query I
SELECT spanset_hash(intspanset '{[1,2]}') = spanset_hash(intspanset '{[1,2]}');
SELECT hash(intspanset '{[1,2]}') = hash(intspanset '{[1,2]}');
----
true

query I
SELECT spanset_hash_extended(intspanset '{[1,2]}', 1) = spanset_hash_extended(intspanset '{[1,2]}', 1);
SELECT hashExtended(intspanset '{[1,2]}', 1) = hashExtended(intspanset '{[1,2]}', 1);
----
true

Expand Down
12 changes: 6 additions & 6 deletions test/sql/temporal_hash.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ require mobilityduck

# temporal_hash returns the uint32 hash as the native UINTEGER
query I
SELECT temporal_hash(tint '1@2000-01-01');
SELECT hash(tint '1@2000-01-01');
----
157457912

query I
SELECT typeof(temporal_hash(tint '1@2000-01-01'));
SELECT typeof(hash(tint '1@2000-01-01'));
----
UINTEGER

# temporal_hash_extended returns the uint64 hash as the native UBIGINT. This value
# (> 2**63) does NOT fit in a signed BIGINT — proof that UBIGINT is required.
query I
SELECT temporal_hash_extended(tint '1@2000-01-01', 0);
SELECT hashExtended(tint '1@2000-01-01', 0);
----
11445401048662056440

query I
SELECT typeof(temporal_hash_extended(tint '1@2000-01-01', 0));
SELECT typeof(hashExtended(tint '1@2000-01-01', 0));
----
UBIGINT

# the seed changes the hash (0 vs 42)
query I
SELECT temporal_hash_extended(tint '1@2000-01-01', 42);
SELECT hashExtended(tint '1@2000-01-01', 42);
----
10824501823241357556

# inherited over every temporal family via Temporal<T>
query I
SELECT temporal_hash_extended(tfloat '1.5@2000-01-01', 42);
SELECT hashExtended(tfloat '1.5@2000-01-01', 42);
----
17681145013286498633
Loading
Loading