Skip to content

Commit

Permalink
Fix unix build
Browse files Browse the repository at this point in the history
  • Loading branch information
lriggs committed Jul 12, 2023
1 parent a5d9271 commit 6ff328e
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cpp/src/arrow/c/bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/arrow/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,10 @@ StructType::StructType(const std::vector<std::shared_ptr<Field>>& fields)
children_ = fields;
}

StructType::StructType()
: NestedType(Type::STRUCT) {
}

StructType::~StructType() {}

std::string StructType::ToString() const {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/arrow/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,9 @@ class ARROW_EXPORT StructType : public NestedType {
static constexpr const char* type_name() { return "struct"; }

explicit StructType(const std::vector<std::shared_ptr<Field>>& fields);
explicit StructType();
StructType(const StructType& rhs) = delete;
StructType& operator=(const StructType& rhs) = delete;

~StructType() override;

Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/type_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ class StringArray;
class StringBuilder;
struct StringScalar;

class StructType;
class StructArray;
class StructBuilder;
struct StructScalar;

class LargeStringType;
class LargeStringArray;
class LargeStringBuilder;
Expand Down Expand Up @@ -454,6 +459,7 @@ ARROW_EXPORT const std::shared_ptr<DataType>& float32();
ARROW_EXPORT const std::shared_ptr<DataType>& float64();
/// \brief Return a StringType instance
ARROW_EXPORT const std::shared_ptr<DataType>& utf8();
ARROW_EXPORT const std::shared_ptr<DataType>& structType();
/// \brief Return a LargeStringType instance
ARROW_EXPORT const std::shared_ptr<DataType>& large_utf8();
/// \brief Return a BinaryType instance
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/gandiva/function_registry_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ std::vector<NativeFunction> 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),
Expand Down
58 changes: 58 additions & 0 deletions cpp/src/gandiva/precompiled/string_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(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_struct*>(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<ArrayBuilder> tmp;
MakeBuilder(pool_, s, &tmp);
//std::vector<int> list_lengths = {42, 43};
//std::vector<int> list_offsets = {142, 143};
//410 ListBuilder* list_vb = checked_cast<ListBuilder*>(builder_->field_builder(0));
Int32Builder* int_vb = checked_cast<Int32Builder*>(builder_->field_builder(0));
Int32Builder* int_vb2 = checked_cast<Int32Builder*>(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) {
Expand Down
12 changes: 12 additions & 0 deletions cpp/src/gandiva/precompiled/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 6ff328e

Please sign in to comment.