Skip to content

Instantly share code, notes, and snippets.

@fsaintjacques
Created March 15, 2019 18:39
Show Gist options
  • Save fsaintjacques/c679ddf51ac750e1f22e0d4c9be604cb to your computer and use it in GitHub Desktop.
Save fsaintjacques/c679ddf51ac750e1f22e0d4c9be604cb to your computer and use it in GitHub Desktop.
template <typename ArrowType, CompareOperator Op>
static inline std::shared_ptr<FilterFunction> MakeCompareFunctionTypeOp(
FunctionContext* ctx) {
return std::static_pointer_cast<FilterFunction>(
std::make_shared<CompareFunction<ArrowType, Op>>(ctx));
}
template <typename ArrowType>
static inline std::shared_ptr<FilterFunction> MakeCompareFilterFunctionType(
FunctionContext* ctx, struct CompareOptions options) {
switch (options.op) {
case CompareOperator::EQUAL:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::EQUAL>(ctx);
case CompareOperator::NOT_EQUAL:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::NOT_EQUAL>(ctx);
case CompareOperator::GREATER:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::GREATER>(ctx);
case CompareOperator::GREATER_EQUAL:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::GREATER_EQUAL>(ctx);
case CompareOperator::LOWER:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::LOWER>(ctx);
case CompareOperator::LOWER_EQUAL:
return MakeCompareFunctionTypeOp<ArrowType, CompareOperator::LOWER_EQUAL>(ctx);
}
return nullptr;
}
std::shared_ptr<FilterFunction> MakeCompareFilterFunction(FunctionContext* ctx,
const DataType& type,
struct CompareOptions options) {
switch (type.id()) {
case UInt8Type::type_id:
return MakeCompareFilterFunctionType<UInt8Type>(ctx, options);
case Int8Type::type_id:
return MakeCompareFilterFunctionType<Int8Type>(ctx, options);
case UInt16Type::type_id:
return MakeCompareFilterFunctionType<UInt16Type>(ctx, options);
case Int16Type::type_id:
return MakeCompareFilterFunctionType<Int16Type>(ctx, options);
case UInt32Type::type_id:
return MakeCompareFilterFunctionType<UInt32Type>(ctx, options);
case Int32Type::type_id:
return MakeCompareFilterFunctionType<Int32Type>(ctx, options);
case UInt64Type::type_id:
return MakeCompareFilterFunctionType<UInt64Type>(ctx, options);
case Int64Type::type_id:
return MakeCompareFilterFunctionType<Int64Type>(ctx, options);
case FloatType::type_id:
return MakeCompareFilterFunctionType<FloatType>(ctx, options);
case DoubleType::type_id:
return MakeCompareFilterFunctionType<DoubleType>(ctx, options);
case Date32Type::type_id:
return MakeCompareFilterFunctionType<Date32Type>(ctx, options);
case Date64Type::type_id:
return MakeCompareFilterFunctionType<Date64Type>(ctx, options);
case TimestampType::type_id:
return MakeCompareFilterFunctionType<TimestampType>(ctx, options);
case Time32Type::type_id:
return MakeCompareFilterFunctionType<Time32Type>(ctx, options);
case Time64Type::type_id:
return MakeCompareFilterFunctionType<Time64Type>(ctx, options);
default:
return nullptr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment