forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GDV-82:[Java][CPP]Export supported types from Gandiva. (apache#66)
Exporting supported data types and functions from Gandiva. Added a JNI bridge to access this from the java layer.
- Loading branch information
1 parent
32c8ee8
commit 6894ed9
Showing
17 changed files
with
559 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2017-2018 Dremio Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#ifndef GANDIVA_TYPES_H | ||
#define GANDIVA_TYPES_H | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "gandiva/arrow.h" | ||
#include "gandiva/function_signature.h" | ||
#include "gandiva/gandiva_aliases.h" | ||
|
||
namespace gandiva { | ||
|
||
class NativeFunction; | ||
class FunctionRegistry; | ||
/// \brief Exports types supported by Gandiva for processing. | ||
/// | ||
/// Has helper methods for clients to programatically discover | ||
/// data types and functions supported by Gandiva. | ||
class ExpressionRegistry { | ||
public: | ||
using iterator = const NativeFunction *; | ||
ExpressionRegistry(); | ||
~ExpressionRegistry(); | ||
static DataTypeVector supported_types() { return supported_types_; } | ||
class FunctionSignatureIterator { | ||
public: | ||
FunctionSignatureIterator(iterator begin, iterator end) : it(begin), end(end) {} | ||
|
||
bool operator!=(const FunctionSignatureIterator &func_sign_it); | ||
|
||
FunctionSignature operator*(); | ||
|
||
iterator operator++(int); | ||
|
||
private: | ||
iterator it; | ||
iterator end; | ||
}; | ||
const FunctionSignatureIterator function_signature_begin(); | ||
const FunctionSignatureIterator function_signature_end() const; | ||
|
||
private: | ||
static DataTypeVector supported_types_; | ||
static DataTypeVector InitSupportedTypes(); | ||
static void AddArrowTypesToVector(arrow::Type::type &type, DataTypeVector &vector); | ||
std::unique_ptr<FunctionRegistry> function_registry_; | ||
}; | ||
} // namespace gandiva | ||
#endif // GANDIVA_TYPES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// Copyright (C) 2017-2018 Dremio Corporation | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "gandiva/expression_registry.h" | ||
|
||
#include "boost/iterator/transform_iterator.hpp" | ||
|
||
#include "codegen/function_registry.h" | ||
#include "codegen/llvm_types.h" | ||
|
||
namespace gandiva { | ||
|
||
ExpressionRegistry::ExpressionRegistry() { | ||
function_registry_.reset(new FunctionRegistry()); | ||
} | ||
|
||
ExpressionRegistry::~ExpressionRegistry() {} | ||
|
||
const ExpressionRegistry::FunctionSignatureIterator | ||
ExpressionRegistry::function_signature_begin() { | ||
return FunctionSignatureIterator(function_registry_->begin(), | ||
function_registry_->end()); | ||
} | ||
|
||
const ExpressionRegistry::FunctionSignatureIterator | ||
ExpressionRegistry::function_signature_end() const { | ||
return FunctionSignatureIterator(function_registry_->end(), function_registry_->end()); | ||
} | ||
|
||
bool ExpressionRegistry::FunctionSignatureIterator::operator!=( | ||
const FunctionSignatureIterator &func_sign_it) { | ||
return func_sign_it.it != this->it; | ||
} | ||
|
||
FunctionSignature ExpressionRegistry::FunctionSignatureIterator::operator*() { | ||
return (*it).signature(); | ||
} | ||
|
||
ExpressionRegistry::iterator ExpressionRegistry::FunctionSignatureIterator::operator++( | ||
int increment) { | ||
return it++; | ||
} | ||
|
||
DataTypeVector ExpressionRegistry::supported_types_ = | ||
ExpressionRegistry::InitSupportedTypes(); | ||
|
||
DataTypeVector ExpressionRegistry::InitSupportedTypes() { | ||
DataTypeVector data_type_vector; | ||
llvm::LLVMContext llvm_context; | ||
LLVMTypes llvm_types(llvm_context); | ||
auto supported_arrow_types = llvm_types.GetSupportedArrowTypes(); | ||
for (auto &type_id : supported_arrow_types) { | ||
AddArrowTypesToVector(type_id, data_type_vector); | ||
} | ||
return data_type_vector; | ||
} | ||
|
||
void ExpressionRegistry::AddArrowTypesToVector(arrow::Type::type &type, | ||
DataTypeVector &vector) { | ||
switch (type) { | ||
case arrow::Type::type::BOOL: | ||
vector.push_back(arrow::boolean()); | ||
break; | ||
case arrow::Type::type::UINT8: | ||
vector.push_back(arrow::uint8()); | ||
break; | ||
case arrow::Type::type::INT8: | ||
vector.push_back(arrow::int8()); | ||
break; | ||
case arrow::Type::type::UINT16: | ||
vector.push_back(arrow::uint16()); | ||
break; | ||
case arrow::Type::type::INT16: | ||
vector.push_back(arrow::int16()); | ||
break; | ||
case arrow::Type::type::UINT32: | ||
vector.push_back(arrow::uint32()); | ||
break; | ||
case arrow::Type::type::INT32: | ||
vector.push_back(arrow::int32()); | ||
break; | ||
case arrow::Type::type::UINT64: | ||
vector.push_back(arrow::uint64()); | ||
break; | ||
case arrow::Type::type::INT64: | ||
vector.push_back(arrow::int64()); | ||
break; | ||
case arrow::Type::type::HALF_FLOAT: | ||
vector.push_back(arrow::float16()); | ||
break; | ||
case arrow::Type::type::FLOAT: | ||
vector.push_back(arrow::float32()); | ||
break; | ||
case arrow::Type::type::DOUBLE: | ||
vector.push_back(arrow::float64()); | ||
break; | ||
case arrow::Type::type::STRING: | ||
vector.push_back(arrow::utf8()); | ||
break; | ||
case arrow::Type::type::BINARY: | ||
vector.push_back(arrow::binary()); | ||
break; | ||
case arrow::Type::type::DATE32: | ||
vector.push_back(arrow::date32()); | ||
break; | ||
case arrow::Type::type::DATE64: | ||
vector.push_back(arrow::date64()); | ||
break; | ||
case arrow::Type::type::TIMESTAMP: | ||
vector.push_back(arrow::timestamp(arrow::TimeUnit::SECOND)); | ||
vector.push_back(arrow::timestamp(arrow::TimeUnit::MILLI)); | ||
vector.push_back(arrow::timestamp(arrow::TimeUnit::NANO)); | ||
vector.push_back(arrow::timestamp(arrow::TimeUnit::MICRO)); | ||
break; | ||
case arrow::Type::type::TIME32: | ||
vector.push_back(arrow::time32(arrow::TimeUnit::SECOND)); | ||
vector.push_back(arrow::time32(arrow::TimeUnit::MILLI)); | ||
break; | ||
case arrow::Type::type::TIME64: | ||
vector.push_back(arrow::time64(arrow::TimeUnit::MICRO)); | ||
vector.push_back(arrow::time64(arrow::TimeUnit::NANO)); | ||
break; | ||
case arrow::Type::type::NA: | ||
vector.push_back(arrow::null()); | ||
break; | ||
case arrow::Type::type::FIXED_SIZE_BINARY: | ||
case arrow::Type::type::MAP: | ||
case arrow::Type::type::INTERVAL: | ||
case arrow::Type::type::DECIMAL: | ||
case arrow::Type::type::LIST: | ||
case arrow::Type::type::STRUCT: | ||
case arrow::Type::type::UNION: | ||
case arrow::Type::type::DICTIONARY: | ||
// un-supported types. test ensures that | ||
// when one of these are added build breaks. | ||
DCHECK(false); | ||
} | ||
} | ||
|
||
} // namespace gandiva |
Oops, something went wrong.