Skip to content

Commit

Permalink
sparksql add unscaled_value function (facebookincubator#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiayi771 authored and JkSelf committed Mar 23, 2023
1 parent 05200e1 commit f06fc00
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
32 changes: 32 additions & 0 deletions velox/functions/sparksql/Decimal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <velox/type/UnscaledShortDecimal.h>
#include "velox/functions/Macros.h"
#include "velox/type/Type.h"

namespace facebook::velox::functions {

template <typename T>
struct UnscaledValueFunction {
VELOX_DEFINE_FUNCTION_TYPES(T);

FOLLY_ALWAYS_INLINE void call(
int64_t& result,
const arg_type<UnscaledShortDecimal>& shortDecimal) {
result = shortDecimal.unscaledValue();
}
};
} // namespace facebook::velox::functions
6 changes: 4 additions & 2 deletions velox/functions/sparksql/Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "velox/functions/sparksql/CompareFunctionsNullSafe.h"
#include "velox/functions/sparksql/DateTime.h"
#include "velox/functions/sparksql/DateTimeFunctions.h"
#include "velox/functions/sparksql/Decimal.h"
#include "velox/functions/sparksql/Hash.h"
#include "velox/functions/sparksql/In.h"
#include "velox/functions/sparksql/LeastGreatest.h"
Expand Down Expand Up @@ -220,8 +221,9 @@ void registerFunctions(const std::string& prefix) {
registerFunction<DateAddFunction, Date, Date, int32_t>({"date_add"});
registerFunction<DateAddFunction, Date, Date, int16_t>({"date_add"});
registerFunction<DateAddFunction, Date, Date, int8_t>({"date_add"});
registerFunction<DateDiffFunction, int32_t, Date, Date>(
{"date_diff"});
registerFunction<DateDiffFunction, int32_t, Date, Date>({"date_diff"});
registerFunction<UnscaledValueFunction, int64_t, UnscaledShortDecimal>(
{prefix + "unscaled_value"});
}

} // namespace sparksql
Expand Down

0 comments on commit f06fc00

Please sign in to comment.