From 6ff328ed6e31230b20e1133aa5a9f83f32ea9599 Mon Sep 17 00:00:00 2001 From: Logan Riggs Date: Wed, 12 Jul 2023 10:45:24 -0700 Subject: [PATCH] Fix unix build --- cpp/src/arrow/c/bridge.cc | 2 +- cpp/src/arrow/type.cc | 5 ++ cpp/src/arrow/type.h | 3 ++ cpp/src/arrow/type_fwd.h | 6 +++ cpp/src/gandiva/function_registry_string.cc | 8 +++ cpp/src/gandiva/precompiled/string_ops.cc | 58 +++++++++++++++++++++ cpp/src/gandiva/precompiled/types.h | 12 +++++ 7 files changed, 93 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/c/bridge.cc b/cpp/src/arrow/c/bridge.cc index 85a5156d11db2..32dbc088a7118 100644 --- a/cpp/src/arrow/c/bridge.cc +++ b/cpp/src/arrow/c/bridge.cc @@ -195,7 +195,7 @@ struct SchemaExporter { } Status ExportSchema(const Schema& schema) { - static const StructType dummy_struct_type({}); + static const StructType dummy_struct_type = StructType(); flags_ = 0; RETURN_NOT_OK(ExportFormat(dummy_struct_type)); diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc index 4804570bdf52f..60b71cbb71df7 100644 --- a/cpp/src/arrow/type.cc +++ b/cpp/src/arrow/type.cc @@ -856,6 +856,10 @@ StructType::StructType(const std::vector>& fields) children_ = fields; } +StructType::StructType() + : NestedType(Type::STRUCT) { +} + StructType::~StructType() {} std::string StructType::ToString() const { @@ -2527,6 +2531,7 @@ TYPE_FACTORY(float16, HalfFloatType) TYPE_FACTORY(float32, FloatType) TYPE_FACTORY(float64, DoubleType) TYPE_FACTORY(utf8, StringType) +TYPE_FACTORY(structType, StructType) TYPE_FACTORY(large_utf8, LargeStringType) TYPE_FACTORY(binary, BinaryType) TYPE_FACTORY(large_binary, LargeBinaryType) diff --git a/cpp/src/arrow/type.h b/cpp/src/arrow/type.h index 560805535dc4f..2957065f18e77 100644 --- a/cpp/src/arrow/type.h +++ b/cpp/src/arrow/type.h @@ -1079,6 +1079,9 @@ class ARROW_EXPORT StructType : public NestedType { static constexpr const char* type_name() { return "struct"; } explicit StructType(const std::vector>& fields); + explicit StructType(); + StructType(const StructType& rhs) = delete; + StructType& operator=(const StructType& rhs) = delete; ~StructType() override; diff --git a/cpp/src/arrow/type_fwd.h b/cpp/src/arrow/type_fwd.h index 657abbaecc42b..450ed9a136d26 100644 --- a/cpp/src/arrow/type_fwd.h +++ b/cpp/src/arrow/type_fwd.h @@ -123,6 +123,11 @@ class StringArray; class StringBuilder; struct StringScalar; +class StructType; +class StructArray; +class StructBuilder; +struct StructScalar; + class LargeStringType; class LargeStringArray; class LargeStringBuilder; @@ -454,6 +459,7 @@ ARROW_EXPORT const std::shared_ptr& float32(); ARROW_EXPORT const std::shared_ptr& float64(); /// \brief Return a StringType instance ARROW_EXPORT const std::shared_ptr& utf8(); +ARROW_EXPORT const std::shared_ptr& structType(); /// \brief Return a LargeStringType instance ARROW_EXPORT const std::shared_ptr& large_utf8(); /// \brief Return a BinaryType instance diff --git a/cpp/src/gandiva/function_registry_string.cc b/cpp/src/gandiva/function_registry_string.cc index 2bc6936d77b3c..dc0f6a8e1d343 100644 --- a/cpp/src/gandiva/function_registry_string.cc +++ b/cpp/src/gandiva/function_registry_string.cc @@ -263,6 +263,14 @@ std::vector GetStringFunctionRegistry() { NativeFunction::kNeedsFunctionHolder | NativeFunction::kCanReturnErrors), + NativeFunction("geo_hash_encode", {}, DataTypeVector{float64(), float64()}, + utf8(), kResultNullIfNull, "gdv_fn_geo_hash_encode_float64_float64", + NativeFunction::kNeedsContext), + + NativeFunction("geo_hash_decode", {}, DataTypeVector{utf8()}, + arrow::structType(), kResultNullIfNull, "gdv_fn_geo_hash_decode_utf8", + NativeFunction::kNeedsContext), + NativeFunction("concatOperator", {}, DataTypeVector{utf8(), utf8()}, utf8(), kResultNullIfNull, "concatOperator_utf8_utf8", NativeFunction::kNeedsContext), diff --git a/cpp/src/gandiva/precompiled/string_ops.cc b/cpp/src/gandiva/precompiled/string_ops.cc index c255b9a11c084..fc73aa7a55819 100644 --- a/cpp/src/gandiva/precompiled/string_ops.cc +++ b/cpp/src/gandiva/precompiled/string_ops.cc @@ -827,6 +827,64 @@ const char* substr_utf8_int64(gdv_int64 context, const char* input, gdv_int32 in return substr_utf8_int64_int64(context, input, in_len, offset64, in_len, out_len); } +FORCE_INLINE +const char* gdv_fn_geo_hash_encode_float64_float64(gdv_int64 context, gdv_float64 lat, gdv_float64 lon, + gdv_int32* out_len) { + //if (repeat_number == 0 || in_len <= 0) { + // *out_len = 0; + // return ""; + //} + + + //Gandiva-blarg + *out_len = 14; + char* ret = reinterpret_cast(gdv_fn_context_arena_malloc(context, *out_len)); + if (ret == nullptr) { + gdv_fn_context_set_error_msg(context, "Could not allocate memory for output string"); + *out_len = 0; + return ""; + } + + std::string out_string = "Gandiva-blarg"; + memcpy(ret, out_string.c_str(), *out_len); + return ret; +} + +FORCE_INLINE +const gdv_struct* gdv_fn_geo_hash_decode_utf8(gdv_int64 context, const char* input, gdv_int32 in_len) { + gdv_struct* ret = reinterpret_cast(gdv_fn_context_arena_malloc(context, sizeof(gdv_struct))); + ret->lat = 42; + ret->lon = 142; + return ret; + + //if (repeat_number == 0 || in_len <= 0) { + // *out_len = 0; + // return ""; + //} + + /*auto s = arrow::struct_({field("a", arrow::int32(), false), field("b", arrow::int32(), false)}); + + MemoryPool* pool_ = default_memory_pool(); + std::unique_ptr tmp; + MakeBuilder(pool_, s, &tmp); + + + +//std::vector list_lengths = {42, 43}; +//std::vector list_offsets = {142, 143}; +//410 ListBuilder* list_vb = checked_cast(builder_->field_builder(0)); + Int32Builder* int_vb = checked_cast(builder_->field_builder(0)); + Int32Builder* int_vb2 = checked_cast(builder_->field_builder(1)); +//420 ASSERT_OK(list_vb->AppendValues(list_offsets.data(), list_offsets.size(), +//421 list_is_valid.data())); + + int_vb->UnsafeAppend(42); + int_vb->UnsafeAppend(43); + int_vb2->UnsafeAppend(142); + int_vb2->UnsafeAppend(143); +*/ +} + FORCE_INLINE const char* repeat_utf8_int32(gdv_int64 context, const char* in, gdv_int32 in_len, gdv_int32 repeat_number, gdv_int32* out_len) { diff --git a/cpp/src/gandiva/precompiled/types.h b/cpp/src/gandiva/precompiled/types.h index 83bbdee208562..2f42355b4ca50 100644 --- a/cpp/src/gandiva/precompiled/types.h +++ b/cpp/src/gandiva/precompiled/types.h @@ -41,6 +41,13 @@ using gdv_utf8 = char*; using gdv_binary = char*; using gdv_day_time_interval = int64_t; +struct GeoStruct { + int32_t lat; + int32_t lon; +}; + +using gdv_struct = GeoStruct; + #ifdef GANDIVA_UNIT_TEST // unit tests may be compiled without O2, so inlining may not happen. #define FORCE_INLINE @@ -464,6 +471,11 @@ gdv_int64 truncate_int64_int32(gdv_int64 in, gdv_int32 out_scale); const char* repeat_utf8_int32(gdv_int64 context, const char* in, gdv_int32 in_len, gdv_int32 repeat_times, gdv_int32* out_len); +const char* gdv_fn_geo_hash_encode_float64_float64(gdv_int64 context, gdv_float64 lat, gdv_float64 lon, + gdv_int32* out_len); + +const gdv_struct* gdv_fn_geo_hash_decode_utf8(gdv_int64 context, const char* input, gdv_int32 in_len); + const char* substr_utf8_int64_int64(gdv_int64 context, const char* input, gdv_int32 in_len, gdv_int64 offset64, gdv_int64 length, gdv_int32* out_len);