forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
155 additions
and
2 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
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,47 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#include "velox/expression/tests/ArgGenerator.h" | ||
#include "velox/functions/sparksql/DecimalUtil.h" | ||
|
||
namespace facebook::velox::functions::sparksql::test { | ||
|
||
class AddSubtractArgGenerator | ||
: public facebook::velox::test::DecimalArgGeneratorBase { | ||
public: | ||
AddSubtractArgGenerator() { | ||
initialize(); | ||
} | ||
|
||
protected: | ||
std::optional<std::pair<int, int>> toReturnType(int count, ...) override { | ||
VELOX_CHECK_EQ(count, 4); | ||
va_list args; | ||
va_start(args, count); | ||
const int p1 = va_arg(args, int); | ||
const int s1 = va_arg(args, int); | ||
const int p2 = va_arg(args, int); | ||
const int s2 = va_arg(args, int); | ||
va_end(args); | ||
|
||
const auto precision = std::max(p1 - s1, p2 - s2) + std::max(s1, s2) + 1; | ||
const auto scale = max(s1, s2); | ||
return DecimalUtil::adjustPrecisionScale(precision, scale); | ||
} | ||
}; | ||
|
||
} // namespace facebook::velox::functions::sparksql::test |
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,47 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#include "velox/expression/tests/ArgGenerator.h" | ||
#include "velox/functions/sparksql/DecimalUtil.h" | ||
|
||
namespace facebook::velox::functions::sparksql::test { | ||
|
||
class DivideArgGenerator | ||
: public facebook::velox::test::DecimalArgGeneratorBase { | ||
public: | ||
DivideArgGenerator() { | ||
initialize(); | ||
} | ||
|
||
protected: | ||
std::optional<std::pair<int, int>> toReturnType(int count, ...) override { | ||
VELOX_CHECK_EQ(count, 4); | ||
va_list args; | ||
va_start(args, count); | ||
const int p1 = va_arg(args, int); | ||
const int s1 = va_arg(args, int); | ||
const int p2 = va_arg(args, int); | ||
const int s2 = va_arg(args, int); | ||
va_end(args); | ||
|
||
const auto scale = std::max(6, s1 + p2 + 1); | ||
const auto precision = p1 - s1 + s2 + scale; | ||
return DecimalUtil::adjustPrecisionScale(precision, scale); | ||
} | ||
}; | ||
|
||
} // namespace facebook::velox::functions::sparksql::test |
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,45 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#pragma once | ||
|
||
#include "velox/expression/tests/ArgGenerator.h" | ||
#include "velox/functions/sparksql/DecimalUtil.h" | ||
|
||
namespace facebook::velox::functions::sparksql::test { | ||
|
||
class MultiplyArgGenerator | ||
: public facebook::velox::test::DecimalArgGeneratorBase { | ||
public: | ||
MultiplyArgGenerator() { | ||
initialize(); | ||
} | ||
|
||
protected: | ||
std::optional<std::pair<int, int>> toReturnType(int count, ...) override { | ||
VELOX_CHECK_EQ(count, 4); | ||
va_list args; | ||
va_start(args, count); | ||
const int p1 = va_arg(args, int); | ||
const int s1 = va_arg(args, int); | ||
const int p2 = va_arg(args, int); | ||
const int s2 = va_arg(args, int); | ||
va_end(args); | ||
|
||
return DecimalUtil::adjustPrecisionScale(p1 + p2 + 1, s1 + s2); | ||
} | ||
}; | ||
|
||
} // namespace facebook::velox::functions::sparksql::test |