baidu palo

This commit is contained in:
cyongli
2017-08-11 17:51:21 +08:00
commit e2311f656e
1988 changed files with 586941 additions and 0 deletions

View File

@ -0,0 +1,74 @@
// Modifications copyright (C) 2017, Baidu.com, Inc.
// Copyright 2017 The Apache Software Foundation
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 "exprs/hll_hash_function.h"
#include "exprs/expr.h"
#include "runtime/tuple_row.h"
#include "runtime/datetime_value.h"
#include "util/path_builder.h"
#include "runtime/string_value.hpp"
#include "exprs/aggregate_functions.h"
#include "exprs/cast_functions.h"
#include "olap/olap_common.h"
#include "olap/utils.h"
namespace palo {
using palo_udf::BigIntVal;
using palo_udf::StringVal;
void HllHashFunctions::init() {
}
StringVal HllHashFunctions::create_string_result(palo_udf::FunctionContext* ctx,
const StringVal& val, const bool is_null) {
std::string result;
if (is_null) {
// HLL_DATA_EMPTY
result = "0";
} else {
// HLL_DATA_EXPLHLL_DATA_EXPLICIT
uint64_t hash = HashUtil::murmur_hash64A(val.ptr, val.len, HashUtil::MURMUR_SEED);
char buf[10];
buf[0] = HLL_DATA_EXPLICIT;
buf[1] = 1;
*((uint64_t*)(buf + 2)) = hash;
result = std::string(buf, 10);
}
return AnyValUtil::from_buffer_temp(ctx, result.c_str(), result.length());
}
StringVal HllHashFunctions::hll_hash(palo_udf::FunctionContext* ctx,
const StringVal& input) {
return create_string_result(ctx, input, input.is_null);
}
StringVal HllHashFunctions::hll_cardinality(palo_udf::FunctionContext* ctx,
const StringVal& input) {
if (input.is_null) {
return StringVal::null();
}
StringVal dst;
AggregateFunctions::hll_union_agg_init(ctx, &dst);
AggregateFunctions::hll_union_agg_update(ctx, input, &dst);
return AggregateFunctions::hll_union_agg_finalize(ctx, dst);
}
}