Skip to content

Commit

Permalink
Support compile on macos (#388)
Browse files Browse the repository at this point in the history
* Support compile on macos

---------

Co-authored-by: youxiduo <youxiduo@corp.netease.com>
  • Loading branch information
ulysses-you and ulysses-you committed Aug 12, 2023
1 parent 686cbbe commit 175870d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 26 deletions.
7 changes: 6 additions & 1 deletion scripts/setup-helper-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ function cmake_install {
-DBUILD_TESTING=OFF \
"$@"
ninja -C "${BINARY_DIR}"
sudo ninja -C "${BINARY_DIR}" install
local OS=`uname -s`
if [ $OS == 'Darwin' ]; then
ninja -C "${BINARY_DIR}" install
else
sudo ninja -C "${BINARY_DIR}" install
fi
}

2 changes: 1 addition & 1 deletion velox/common/caching/AsyncDataCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace facebook::velox::cache {
class AsyncDataCache;
class CacheShard;
class SsdCache;
class SsdCacheStats;
struct SsdCacheStats;
class SsdFile;

// Type for tracking last access. This is based on CPU clock and
Expand Down
2 changes: 1 addition & 1 deletion velox/dwio/dwrf/common/RLEv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class RleDecoderV2 : public dwio::common::IntDecoder<isSigned> {
*/
void next(int64_t* data, uint64_t numValues, const uint64_t* nulls) override;

void nextLengths(int32_t* const data, const int32_t numValues) {
void nextLengths(int32_t* const data, const int32_t numValues) override {
for (int i = 0; i < numValues; ++i) {
data[i] = readValue();
}
Expand Down
13 changes: 8 additions & 5 deletions velox/exec/AggregationHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AggregationHook : public ValueHook {

std::string toString() const override {
char buf[256];
sprintf(buf, "AggregationHook kind:%d", (int)kind());
snprintf(buf, sizeof(buf), "AggregationHook kind:%d", (int)kind());
return buf;
}

Expand Down Expand Up @@ -131,8 +131,9 @@ class SumHook final : public AggregationHook {

std::string toString() const override {
char buf[256];
sprintf(
snprintf(
buf,
sizeof(buf),
"SumHook kind:%d TValue:%s TAggregate:%s",
(int)kind(),
typeid(TValue).name(),
Expand Down Expand Up @@ -182,9 +183,10 @@ class SimpleCallableHook final : public AggregationHook {
updateSingleValue_(updateSingleValue) {}

std::string toString() const override {
char buf[256];
sprintf(
char buf[384];
snprintf(
buf,
sizeof(buf),
"SimpleCallableHook kind:%d TValue:%s TAggregate:%s UpdateSingleValue:%s",
(int)kind(),
typeid(TValue).name(),
Expand Down Expand Up @@ -222,8 +224,9 @@ class MinMaxHook final : public AggregationHook {

std::string toString() const override {
char buf[256];
sprintf(
snprintf(
buf,
sizeof(buf),
"MinMaxHook kind:%d T:%s isMin:%d",
(int)kind(),
typeid(T).name(),
Expand Down
2 changes: 1 addition & 1 deletion velox/exec/TaskStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LocalExchangeMemoryManager;
class LocalExchangeSource;
class MergeSource;
class MergeJoinSource;
class Split;
struct Split;
class SpillOperatorGroup;

/// Corresponds to Presto TaskState, needed for reporting query completion.
Expand Down
3 changes: 2 additions & 1 deletion velox/exec/tests/utils/PlanBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ PlanBuilder& PlanBuilder::expand(
field(planNode_->outputType(), projectionSet[i]));
} else {
projectExprs.push_back(std::make_shared<core::ConstantTypedExpr>(
BIGINT(), variant(std::stol(projectionSet[i]))));
BIGINT(),
variant(static_cast<int64_t>(std::stol(projectionSet[i])))));
}
}
projectSetExprs.push_back(projectExprs);
Expand Down
6 changes: 4 additions & 2 deletions velox/functions/sparksql/DecimalArithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,12 +479,14 @@ class Multiply {
int32_t countLeadingZerosA = 0;
int32_t countLeadingZerosB = 0;
if constexpr (std::is_same_v<A, int128_t>) {
countLeadingZerosA = bits::countLeadingZerosUint128(std::abs(a));
countLeadingZerosA =
bits::countLeadingZerosUint128(DecimalUtil::absInt128(a));
} else {
countLeadingZerosA = bits::countLeadingZeros(a);
}
if constexpr (std::is_same_v<R, int128_t>) {
countLeadingZerosB = bits::countLeadingZerosUint128(std::abs(b));
countLeadingZerosB =
bits::countLeadingZerosUint128(DecimalUtil::absInt128(b));
} else {
countLeadingZerosB = bits::countLeadingZeros(b);
}
Expand Down
17 changes: 14 additions & 3 deletions velox/type/DecimalUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ class DecimalUtil {
/// Helper function to convert a decimal value to string.
static std::string toString(const int128_t value, const TypePtr& type);

// Helper function to be compatible with macos whose `std::abs` does not
// support int128_t.
static int128_t absInt128(int128_t __x) {
#ifdef __APPLE__
int128_t __sgn = __x >> (16 * CHAR_BIT - 1);
return (__x ^ __sgn) - __sgn;
#else
return std::abs(__x);
#endif
}

template <typename TInput, typename TOutput>
inline static std::optional<TOutput> rescaleWithRoundUp(
const TInput inputValue,
Expand Down Expand Up @@ -150,7 +161,7 @@ class DecimalUtil {

// convert scaled double to int128
int32_t sign = unscaled < 0 ? -1 : 1;
auto unscaled_abs = std::abs(unscaled);
auto unscaled_abs = absInt128(unscaled);

uint64_t high_bits = static_cast<uint64_t>(std::ldexp(unscaled_abs, -64));
uint64_t low_bits = static_cast<uint64_t>(
Expand Down Expand Up @@ -422,7 +433,7 @@ class DecimalUtil {
new_value = value;
sig = 1;
} else if (value < 0) {
new_value = std::abs(value);
new_value = absInt128(value);
sig = -1;
} else {
new_value = value;
Expand Down Expand Up @@ -473,7 +484,7 @@ class DecimalUtil {
new_value = value;
sig = 1;
} else if (value < 0) {
new_value = std::abs(value);
new_value = absInt128(value);
sig = -1;
} else {
new_value = value;
Expand Down
17 changes: 6 additions & 11 deletions velox/type/DecimalUtilOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ class DecimalUtilOp {
const A& num,
uint8_t aRescale) {
auto value = num;
auto valueAbs = std::abs(value);
int32_t num_occupied = 0;
if constexpr (std::is_same_v<A, int64_t>) {
auto valueAbs = std::abs(value);
num_occupied = 64 - bits::countLeadingZeros(valueAbs);
} else {
num_occupied = 128 - bits::countLeadingZerosUint128(std::abs(num));
num_occupied =
128 - bits::countLeadingZerosUint128(DecimalUtil::absInt128(num));
}

return num_occupied + maxBitsRequiredIncreaseAfterScaling(aRescale);
Expand All @@ -122,18 +123,15 @@ class DecimalUtilOp {
template <typename A, typename B>
inline static int32_t
minLeadingZeros(const A& a, const B& b, uint8_t aScale, uint8_t bScale) {
auto x_value_abs = std::abs(a);

auto y_value_abs = std::abs(b);
int32_t x_lz = 0;
int32_t y_lz = 0;
if constexpr (std::is_same_v<A, int128_t>) {
x_lz = bits::countLeadingZerosUint128(std::abs(a));
x_lz = bits::countLeadingZerosUint128(DecimalUtil::absInt128(a));
} else {
x_lz = bits::countLeadingZeros(a);
}
if constexpr (std::is_same_v<B, int128_t>) {
y_lz = bits::countLeadingZerosUint128(std::abs(b));
y_lz = bits::countLeadingZerosUint128(DecimalUtil::absInt128(b));
} else {
y_lz = bits::countLeadingZeros(b);
}
Expand Down Expand Up @@ -239,10 +237,7 @@ class DecimalUtilOp {
if constexpr (std::is_same_v<R, int64_t>) {
auto result = convertToInt64(result_large, overflow);
auto remainder = convertToInt64(remainder_large, overflow);
if (!(result >= DecimalUtil::kLongDecimalMin &&
result <= DecimalUtil::kLongDecimalMax)) {
*overflow = true;
} else {
if (!overflow) {
r = result;
}
return remainder;
Expand Down

0 comments on commit 175870d

Please sign in to comment.