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 14, 2023
1 parent 276a774 commit 029117e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 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
3 changes: 3 additions & 0 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 @@ -211,6 +212,8 @@ 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<UnscaledValueFunction, int64_t, UnscaledShortDecimal>(
{prefix + "unscaled_value"});
}

} // namespace sparksql
Expand Down

0 comments on commit 029117e

Please sign in to comment.