Skip to content

Commit

Permalink
apacheGH-37893: [Java] Move Types.proto in a subfolder (apache#37894)
Browse files Browse the repository at this point in the history
### Rationale for this change

Types.proto is a Gandiva protobuf definition used by Gandiva to exchange data between Java and C++. This file is packaged automatically within arrow-gandiva jar but because of its generic name, it may cause conflicts in others' people project.

### What changes are included in this PR?

Move `Types.proto` into `gandiva/types.proto` (also matching convention of using lowercase filename) so that it become less likely to cause a conflict.

### Are these changes tested?

Change should have no impact on the feature itself. Manually check the resulting jar to confirm that `types.proto` is not located at the root of the archive.

### Are there any user-facing changes?

No user-facing. Developers who were actually referencing Gandiva `Types.proto` in their project may have to change their `import` directive.

**This PR includes breaking changes to public APIs.**

* Closes: apache#37893

Authored-by: Laurent Goujon <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
laurentgo authored and etseidl committed Sep 28, 2023
1 parent 6da506f commit 180b5be
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 127 deletions.
10 changes: 5 additions & 5 deletions java/gandiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ add_jar(arrow_java_jni_gandiva_jar
arrow_java_jni_gandiva_headers)

set(GANDIVA_PROTO_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(GANDIVA_PROTO_OUTPUT_FILES "${GANDIVA_PROTO_OUTPUT_DIR}/Types.pb.cc"
"${GANDIVA_PROTO_OUTPUT_DIR}/Types.pb.h")
set(GANDIVA_PROTO_OUTPUT_FILES "${GANDIVA_PROTO_OUTPUT_DIR}/gandiva/types.pb.cc"
"${GANDIVA_PROTO_OUTPUT_DIR}/gandiva/types.pb.h")

set_source_files_properties(${GANDIVA_PROTO_OUTPUT_FILES} PROPERTIES GENERATED TRUE)

set(GANDIVA_PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/proto)
get_filename_component(GANDIVA_PROTO_FILE_ABSOLUTE ${GANDIVA_PROTO_DIR}/Types.proto
ABSOLUTE)
get_filename_component(GANDIVA_PROTO_FILE_ABSOLUTE
${GANDIVA_PROTO_DIR}/gandiva/types.proto ABSOLUTE)

find_package(Protobuf REQUIRED)
add_custom_command(OUTPUT ${GANDIVA_PROTO_OUTPUT_FILES}
COMMAND protobuf::protoc --proto_path ${GANDIVA_PROTO_DIR} --cpp_out
${GANDIVA_PROTO_OUTPUT_DIR} ${GANDIVA_PROTO_FILE_ABSOLUTE}
DEPENDS ${GANDIVA_PROTO_FILE_ABSOLUTE}
COMMENT "Running Protobuf compiler on Types.proto"
COMMENT "Running Protobuf compiler on gandiva/types.proto"
VERBATIM)

add_custom_target(garrow_java_jni_gandiva_proto ALL DEPENDS ${GANDIVA_PROTO_OUTPUT_FILES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// specific language governing permissions and limitations
// under the License.

syntax = "proto2";
package types;
syntax = "proto3";
package gandiva.types;

option java_package = "org.apache.arrow.gandiva.ipc";
option java_outer_classname = "GandivaTypes";
Expand Down
87 changes: 43 additions & 44 deletions java/gandiva/src/main/cpp/expression_registry_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,121 +20,120 @@
#include <arrow/util/logging.h>
#include <gandiva/arrow.h>
#include <gandiva/expression_registry.h>

#include "Types.pb.h"
#include "org_apache_arrow_gandiva_evaluator_ExpressionRegistryJniHelper.h"
#include <gandiva/types.pb.h>
#include <org_apache_arrow_gandiva_evaluator_ExpressionRegistryJniHelper.h>

using gandiva::DataTypePtr;
using gandiva::ExpressionRegistry;

types::TimeUnit MapTimeUnit(arrow::TimeUnit::type& unit) {
gandiva::types::TimeUnit MapTimeUnit(arrow::TimeUnit::type& unit) {
switch (unit) {
case arrow::TimeUnit::MILLI:
return types::TimeUnit::MILLISEC;
return gandiva::types::TimeUnit::MILLISEC;
case arrow::TimeUnit::SECOND:
return types::TimeUnit::SEC;
return gandiva::types::TimeUnit::SEC;
case arrow::TimeUnit::MICRO:
return types::TimeUnit::MICROSEC;
return gandiva::types::TimeUnit::MICROSEC;
case arrow::TimeUnit::NANO:
return types::TimeUnit::NANOSEC;
return gandiva::types::TimeUnit::NANOSEC;
}
// satisfy gcc. should be unreachable.
return types::TimeUnit::SEC;
return gandiva::types::TimeUnit::SEC;
}

void ArrowToProtobuf(DataTypePtr type, types::ExtGandivaType* gandiva_data_type) {
void ArrowToProtobuf(DataTypePtr type, gandiva::types::ExtGandivaType* gandiva_data_type) {
switch (type->id()) {
case arrow::Type::BOOL:
gandiva_data_type->set_type(types::GandivaType::BOOL);
gandiva_data_type->set_type(gandiva::types::GandivaType::BOOL);
break;
case arrow::Type::UINT8:
gandiva_data_type->set_type(types::GandivaType::UINT8);
gandiva_data_type->set_type(gandiva::types::GandivaType::UINT8);
break;
case arrow::Type::INT8:
gandiva_data_type->set_type(types::GandivaType::INT8);
gandiva_data_type->set_type(gandiva::types::GandivaType::INT8);
break;
case arrow::Type::UINT16:
gandiva_data_type->set_type(types::GandivaType::UINT16);
gandiva_data_type->set_type(gandiva::types::GandivaType::UINT16);
break;
case arrow::Type::INT16:
gandiva_data_type->set_type(types::GandivaType::INT16);
gandiva_data_type->set_type(gandiva::types::GandivaType::INT16);
break;
case arrow::Type::UINT32:
gandiva_data_type->set_type(types::GandivaType::UINT32);
gandiva_data_type->set_type(gandiva::types::GandivaType::UINT32);
break;
case arrow::Type::INT32:
gandiva_data_type->set_type(types::GandivaType::INT32);
gandiva_data_type->set_type(gandiva::types::GandivaType::INT32);
break;
case arrow::Type::UINT64:
gandiva_data_type->set_type(types::GandivaType::UINT64);
gandiva_data_type->set_type(gandiva::types::GandivaType::UINT64);
break;
case arrow::Type::INT64:
gandiva_data_type->set_type(types::GandivaType::INT64);
gandiva_data_type->set_type(gandiva::types::GandivaType::INT64);
break;
case arrow::Type::HALF_FLOAT:
gandiva_data_type->set_type(types::GandivaType::HALF_FLOAT);
gandiva_data_type->set_type(gandiva::types::GandivaType::HALF_FLOAT);
break;
case arrow::Type::FLOAT:
gandiva_data_type->set_type(types::GandivaType::FLOAT);
gandiva_data_type->set_type(gandiva::types::GandivaType::FLOAT);
break;
case arrow::Type::DOUBLE:
gandiva_data_type->set_type(types::GandivaType::DOUBLE);
gandiva_data_type->set_type(gandiva::types::GandivaType::DOUBLE);
break;
case arrow::Type::STRING:
gandiva_data_type->set_type(types::GandivaType::UTF8);
gandiva_data_type->set_type(gandiva::types::GandivaType::UTF8);
break;
case arrow::Type::BINARY:
gandiva_data_type->set_type(types::GandivaType::BINARY);
gandiva_data_type->set_type(gandiva::types::GandivaType::BINARY);
break;
case arrow::Type::DATE32:
gandiva_data_type->set_type(types::GandivaType::DATE32);
gandiva_data_type->set_type(gandiva::types::GandivaType::DATE32);
break;
case arrow::Type::DATE64:
gandiva_data_type->set_type(types::GandivaType::DATE64);
gandiva_data_type->set_type(gandiva::types::GandivaType::DATE64);
break;
case arrow::Type::TIMESTAMP: {
gandiva_data_type->set_type(types::GandivaType::TIMESTAMP);
gandiva_data_type->set_type(gandiva::types::GandivaType::TIMESTAMP);
std::shared_ptr<arrow::TimestampType> cast_time_stamp_type =
std::dynamic_pointer_cast<arrow::TimestampType>(type);
arrow::TimeUnit::type unit = cast_time_stamp_type->unit();
types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva::types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva_data_type->set_timeunit(time_unit);
break;
}
case arrow::Type::TIME32: {
gandiva_data_type->set_type(types::GandivaType::TIME32);
gandiva_data_type->set_type(gandiva::types::GandivaType::TIME32);
std::shared_ptr<arrow::Time32Type> cast_time_32_type =
std::dynamic_pointer_cast<arrow::Time32Type>(type);
arrow::TimeUnit::type unit = cast_time_32_type->unit();
types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva::types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva_data_type->set_timeunit(time_unit);
break;
}
case arrow::Type::TIME64: {
gandiva_data_type->set_type(types::GandivaType::TIME32);
gandiva_data_type->set_type(gandiva::types::GandivaType::TIME32);
std::shared_ptr<arrow::Time64Type> cast_time_64_type =
std::dynamic_pointer_cast<arrow::Time64Type>(type);
arrow::TimeUnit::type unit = cast_time_64_type->unit();
types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva::types::TimeUnit time_unit = MapTimeUnit(unit);
gandiva_data_type->set_timeunit(time_unit);
break;
}
case arrow::Type::NA:
gandiva_data_type->set_type(types::GandivaType::NONE);
gandiva_data_type->set_type(gandiva::types::GandivaType::NONE);
break;
case arrow::Type::DECIMAL: {
gandiva_data_type->set_type(types::GandivaType::DECIMAL);
gandiva_data_type->set_type(gandiva::types::GandivaType::DECIMAL);
gandiva_data_type->set_precision(0);
gandiva_data_type->set_scale(0);
break;
}
case arrow::Type::INTERVAL_MONTHS:
gandiva_data_type->set_type(types::GandivaType::INTERVAL);
gandiva_data_type->set_intervaltype(types::IntervalType::YEAR_MONTH);
gandiva_data_type->set_type(gandiva::types::GandivaType::INTERVAL);
gandiva_data_type->set_intervaltype(gandiva::types::IntervalType::YEAR_MONTH);
break;
case arrow::Type::INTERVAL_DAY_TIME:
gandiva_data_type->set_type(types::GandivaType::INTERVAL);
gandiva_data_type->set_intervaltype(types::IntervalType::DAY_TIME);
gandiva_data_type->set_type(gandiva::types::GandivaType::INTERVAL);
gandiva_data_type->set_intervaltype(gandiva::types::IntervalType::DAY_TIME);
break;
default:
// un-supported types. test ensures that
Expand All @@ -146,10 +145,10 @@ void ArrowToProtobuf(DataTypePtr type, types::ExtGandivaType* gandiva_data_type)
JNIEXPORT jbyteArray JNICALL
Java_org_apache_arrow_gandiva_evaluator_ExpressionRegistryJniHelper_getGandivaSupportedDataTypes( // NOLINT
JNIEnv* env, jobject types_helper) {
types::GandivaDataTypes gandiva_data_types;
gandiva::types::GandivaDataTypes gandiva_data_types;
auto supported_types = ExpressionRegistry::supported_types();
for (auto const& type : supported_types) {
types::ExtGandivaType* gandiva_data_type = gandiva_data_types.add_datatype();
gandiva::types::ExtGandivaType* gandiva_data_type = gandiva_data_types.add_datatype();
ArrowToProtobuf(type, gandiva_data_type);
}
auto size = static_cast<int>(gandiva_data_types.ByteSizeLong());
Expand All @@ -169,15 +168,15 @@ JNIEXPORT jbyteArray JNICALL
Java_org_apache_arrow_gandiva_evaluator_ExpressionRegistryJniHelper_getGandivaSupportedFunctions( // NOLINT
JNIEnv* env, jobject types_helper) {
ExpressionRegistry expr_registry;
types::GandivaFunctions gandiva_functions;
gandiva::types::GandivaFunctions gandiva_functions;
for (auto function = expr_registry.function_signature_begin();
function != expr_registry.function_signature_end(); function++) {
types::FunctionSignature* function_signature = gandiva_functions.add_function();
gandiva::types::FunctionSignature* function_signature = gandiva_functions.add_function();
function_signature->set_name((*function).base_name());
types::ExtGandivaType* return_type = function_signature->mutable_returntype();
gandiva::types::ExtGandivaType* return_type = function_signature->mutable_returntype();
ArrowToProtobuf((*function).ret_type(), return_type);
for (auto& param_type : (*function).param_types()) {
types::ExtGandivaType* proto_param_type = function_signature->add_paramtypes();
gandiva::types::ExtGandivaType* proto_param_type = function_signature->add_paramtypes();
ArrowToProtobuf(param_type, proto_param_type);
}
}
Expand Down
Loading

0 comments on commit 180b5be

Please sign in to comment.