Skip to content

Commit

Permalink
Convert Data Types from Uppercase to Lowercase && Modify client seria…
Browse files Browse the repository at this point in the history
…lization
  • Loading branch information
Jax-YHH committed Jul 16, 2024
1 parent 7135ef8 commit 92eaa83
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 99 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ INCLUDE (version)

OPTION (BUILD_BENCHMARK "Build benchmark" OFF)
OPTION (BUILD_TESTS "Build tests" OFF)
OPTION (BUILD_EXAMPLES "Build examples" ON)
OPTION (BUILD_SHARED_LIBS "Build shared libs" OFF)
OPTION (WITH_OPENSSL "Use OpenSSL for TLS connections" OFF)
OPTION (WITH_SYSTEM_ABSEIL "Use system ABSEIL" OFF)
Expand Down
12 changes: 12 additions & 0 deletions clickhouse/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <system_error>
#include <vector>
#include <sstream>
#include <iostream>

#if defined(WITH_OPENSSL)
#include "base/sslsocket.h"
Expand Down Expand Up @@ -795,6 +796,12 @@ void Client::Impl::SendQuery(const Query& query) {
}
}

/// start by Jax
WireFormat::WriteUInt64(*output_, uint64_t(0));//:value
WireFormat::WriteUInt64(*output_, uint64_t(0));//:count_participating_replicas
WireFormat::WriteUInt64(*output_, uint64_t(0));//:number_of_current_replica
/// end by Jax

/// Per query settings
if (server_info_.revision >= DBMS_MIN_REVISION_WITH_SETTINGS_SERIALIZED_AS_STRINGS) {
for(const auto& [name, field] : query.GetQuerySettings()) {
Expand All @@ -817,6 +824,11 @@ void Client::Impl::SendQuery(const Query& query) {
WireFormat::WriteUInt64(*output_, Stages::Complete);
WireFormat::WriteUInt64(*output_, compression_);
WireFormat::WriteString(*output_, query.GetText());

/// start by Jax
std::cout<<"query.GetText(): "<<query.GetText()<<std::endl;
/// end by Jax

// Send empty block as marker of
// end of data
SendData(Block());
Expand Down
92 changes: 46 additions & 46 deletions clickhouse/types/type_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,44 @@ bool TypeAst::operator==(const TypeAst & other) const {
}

static const std::unordered_map<std::string, Type::Code> kTypeCode = {
{ "Void", Type::Void },
{ "Int8", Type::Int8 },
{ "Int16", Type::Int16 },
{ "Int32", Type::Int32 },
{ "Int64", Type::Int64 },
{ "Bool", Type::UInt8 },
{ "UInt8", Type::UInt8 },
{ "UInt16", Type::UInt16 },
{ "UInt32", Type::UInt32 },
{ "UInt64", Type::UInt64 },
{ "Float32", Type::Float32 },
{ "Float64", Type::Float64 },
{ "String", Type::String },
{ "FixedString", Type::FixedString },
{ "DateTime", Type::DateTime },
{ "DateTime64", Type::DateTime64 },
{ "Date", Type::Date },
{ "Date32", Type::Date32 },
{ "Array", Type::Array },
{ "Nullable", Type::Nullable },
{ "Tuple", Type::Tuple },
{ "Enum8", Type::Enum8 },
{ "Enum16", Type::Enum16 },
{ "UUID", Type::UUID },
{ "IPv4", Type::IPv4 },
{ "IPv6", Type::IPv6 },
{ "Int128", Type::Int128 },
// { "UInt128", Type::UInt128 },
{ "Decimal", Type::Decimal },
{ "Decimal32", Type::Decimal32 },
{ "Decimal64", Type::Decimal64 },
{ "Decimal128", Type::Decimal128 },
{ "LowCardinality", Type::LowCardinality },
{ "Map", Type::Map },
{ "Point", Type::Point },
{ "Ring", Type::Ring },
{ "Polygon", Type::Polygon },
{ "MultiPolygon", Type::MultiPolygon },
{ "void", Type::Void },
{ "int8", Type::Int8 },
{ "int16", Type::Int16 },
{ "int32", Type::Int32 },
{ "int64", Type::Int64 },
{ "bool", Type::UInt8 },
{ "uint8", Type::UInt8 },
{ "uint16", Type::UInt16 },
{ "uint32", Type::UInt32 },
{ "uint64", Type::UInt64 },
{ "float32", Type::Float32 },
{ "float64", Type::Float64 },
{ "string", Type::String },
{ "fixed_string", Type::FixedString },
{ "datetime", Type::DateTime },
{ "datetime64", Type::DateTime64 },
{ "date", Type::Date },
{ "date32", Type::Date32 },
{ "array", Type::Array },
{ "nullable", Type::Nullable },
{ "tuple", Type::Tuple },
{ "enum8", Type::Enum8 },
{ "enum16", Type::Enum16 },
{ "uuid", Type::UUID },
{ "ipv4", Type::IPv4 },
{ "ipv6", Type::IPv6 },
{ "int128", Type::Int128 },
// { "uint128", Type::UInt128 },
{ "decimal", Type::Decimal },
{ "decimal32", Type::Decimal32 },
{ "decimal64", Type::Decimal64 },
{ "decimal128", Type::Decimal128 },
{ "lowcardinality", Type::LowCardinality },
{ "map", Type::Map },
{ "point", Type::Point },
{ "ring", Type::Ring },
{ "polygon", Type::Polygon },
{ "multipolygon", Type::MultiPolygon },
};

template <typename L, typename R>
Expand All @@ -90,35 +90,35 @@ static Type::Code GetTypeCode(const std::string& name) {
}

static TypeAst::Meta GetTypeMeta(const StringView& name) {
if (name == "Array") {
if (name == "array") {
return TypeAst::Array;
}

if (name == "Null") {
if (name == "null") {
return TypeAst::Null;
}

if (name == "Nullable") {
if (name == "nullable") {
return TypeAst::Nullable;
}

if (name == "Tuple") {
if (name == "tuple") {
return TypeAst::Tuple;
}

if (name == "Enum8" || name == "Enum16") {
if (name == "enum8" || name == "enum16") {
return TypeAst::Enum;
}

if (name == "LowCardinality") {
if (name == "lowcardinality") {
return TypeAst::LowCardinality;
}

if (name == "SimpleAggregateFunction") {
if (name == "simpleaggregatefunction") {
return TypeAst::SimpleAggregateFunction;
}

if (name == "Map") {
if (name == "map") {
return TypeAst::Map;
}

Expand Down
94 changes: 47 additions & 47 deletions clickhouse/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ Type::Type(const Code code)

const char* Type::TypeName(Type::Code code) {
switch (code) {
case Type::Code::Void: return "Void";
case Type::Code::Int8: return "Int8";
case Type::Code::Int16: return "Int16";
case Type::Code::Int32: return "Int32";
case Type::Code::Int64: return "Int64";
case Type::Code::UInt8: return "UInt8";
case Type::Code::UInt16: return "UInt16";
case Type::Code::UInt32: return "UInt32";
case Type::Code::UInt64: return "UInt64";
case Type::Code::Float32: return "Float32";
case Type::Code::Float64: return "Float64";
case Type::Code::String: return "String";
case Type::Code::FixedString: return "FixedString";
case Type::Code::DateTime: return "DateTime";
case Type::Code::Date: return "Date";
case Type::Code::Array: return "Array";
case Type::Code::Nullable: return "Nullable";
case Type::Code::Tuple: return "Tuple";
case Type::Code::Enum8: return "Enum8";
case Type::Code::Enum16: return "Enum16";
case Type::Code::UUID: return "UUID";
case Type::Code::IPv4: return "IPv4";
case Type::Code::IPv6: return "IPv6";
case Type::Code::Int128: return "Int128";
case Type::Code::Decimal: return "Decimal";
case Type::Code::Decimal32: return "Decimal32";
case Type::Code::Decimal64: return "Decimal64";
case Type::Code::Decimal128: return "Decimal128";
case Type::Code::LowCardinality: return "LowCardinality";
case Type::Code::DateTime64: return "DateTime64";
case Type::Code::Date32: return "Date32";
case Type::Code::Map: return "Map";
case Type::Code::Point: return "Point";
case Type::Code::Ring: return "Ring";
case Type::Code::Polygon: return "Polygon";
case Type::Code::MultiPolygon: return "MultiPolygon";
case Type::Code::Void: return "void";
case Type::Code::Int8: return "int8";
case Type::Code::Int16: return "int16";
case Type::Code::Int32: return "int32";
case Type::Code::Int64: return "int64";
case Type::Code::UInt8: return "uint8";
case Type::Code::UInt16: return "uint16";
case Type::Code::UInt32: return "uint32";
case Type::Code::UInt64: return "uint64";
case Type::Code::Float32: return "float32";
case Type::Code::Float64: return "float64";
case Type::Code::String: return "string";
case Type::Code::FixedString: return "fixed_string";
case Type::Code::DateTime: return "datetime";
case Type::Code::Date: return "date";
case Type::Code::Array: return "array";
case Type::Code::Nullable: return "nullable";
case Type::Code::Tuple: return "tuple";
case Type::Code::Enum8: return "enum8";
case Type::Code::Enum16: return "enum16";
case Type::Code::UUID: return "uuid";
case Type::Code::IPv4: return "ipv4";
case Type::Code::IPv6: return "ipv6";
case Type::Code::Int128: return "int128";
case Type::Code::Decimal: return "decimal";
case Type::Code::Decimal32: return "decimal32";
case Type::Code::Decimal64: return "decimal64";
case Type::Code::Decimal128: return "decimal128";
case Type::Code::LowCardinality: return "lowcardinality";
case Type::Code::DateTime64: return "datetime64";
case Type::Code::Date32: return "date32";
case Type::Code::Map: return "map";
case Type::Code::Point: return "point";
case Type::Code::Ring: return "ring";
case Type::Code::Polygon: return "polygon";
case Type::Code::MultiPolygon: return "multipolygon";
}

return "Unknown type";
Expand Down Expand Up @@ -278,13 +278,13 @@ DecimalType::DecimalType(size_t precision, size_t scale)
std::string DecimalType::GetName() const {
switch (GetCode()) {
case Decimal:
return "Decimal(" + std::to_string(precision_) + "," + std::to_string(scale_) + ")";
return "decimal(" + std::to_string(precision_) + "," + std::to_string(scale_) + ")";
case Decimal32:
return "Decimal32(" + std::to_string(scale_) + ")";
return "decimal32(" + std::to_string(scale_) + ")";
case Decimal64:
return "Decimal64(" + std::to_string(scale_) + ")";
return "decimal64(" + std::to_string(scale_) + ")";
case Decimal128:
return "Decimal128(" + std::to_string(scale_) + ")";
return "decimal128(" + std::to_string(scale_) + ")";
default:
/// XXX: NOT REACHED!
return "";
Expand All @@ -304,9 +304,9 @@ std::string EnumType::GetName() const {
std::string result;

if (GetCode() == Enum8) {
result = "Enum8(";
result = "enum8(";
} else {
result = "Enum16(";
result = "enum16(";
}

for (auto ei = value_to_name_.begin(); ei != value_to_name_.end();) {
Expand Down Expand Up @@ -369,7 +369,7 @@ DateTimeType::DateTimeType(std::string timezone)
}

std::string DateTimeType::GetName() const {
std::string datetime_representation = "DateTime";
std::string datetime_representation = "datetime";
const auto & timezone = Timezone();
if (!timezone.empty())
datetime_representation += "('" + timezone + "')";
Expand All @@ -383,14 +383,14 @@ DateTime64Type::DateTime64Type(size_t precision, std::string timezone)
: Type(DateTime64), details::TypeWithTimeZoneMixin(std::move(timezone)), precision_(precision) {

if (precision_ > 18) {
throw ValidationError("DateTime64 precision is > 18");
throw ValidationError("datetime64 precision is > 18");
}
}

std::string DateTime64Type::GetName() const {
std::string datetime64_representation;
datetime64_representation.reserve(14);
datetime64_representation += "DateTime64(";
datetime64_representation += "datetime64(";
datetime64_representation += std::to_string(precision_);

const auto & timezone = Timezone();
Expand Down Expand Up @@ -425,7 +425,7 @@ LowCardinalityType::~LowCardinalityType() {
}

std::string TupleType::GetName() const {
std::string result("Tuple(");
std::string result("tuple(");

if (!item_types_.empty()) {
result += item_types_[0]->GetName();
Expand All @@ -448,7 +448,7 @@ MapType::MapType(TypeRef key_type, TypeRef value_type)
}

std::string MapType::GetName() const {
return std::string("Map(") + key_type_->GetName() + ", " +value_type_->GetName() + ")";
return std::string("map(") + key_type_->GetName() + ", " +value_type_->GetName() + ")";
}

} // namespace clickhouse
6 changes: 3 additions & 3 deletions clickhouse/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class FixedStringType : public Type {
public:
explicit FixedStringType(size_t n);

std::string GetName() const { return std::string("FixedString(") + std::to_string(size_) + ")"; }
std::string GetName() const { return std::string("fixed_string(") + std::to_string(size_) + ")"; }

inline size_t GetSize() const { return size_; }

Expand All @@ -261,7 +261,7 @@ class NullableType : public Type {
public:
explicit NullableType(TypeRef nested_type);

std::string GetName() const { return std::string("Nullable(") + nested_type_->GetName() + ")"; }
std::string GetName() const { return std::string("nullable(") + nested_type_->GetName() + ")"; }

/// Type of nested nullable element.
TypeRef GetNestedType() const { return nested_type_; }
Expand All @@ -288,7 +288,7 @@ class LowCardinalityType : public Type {
explicit LowCardinalityType(TypeRef nested_type);
~LowCardinalityType();

std::string GetName() const { return std::string("LowCardinality(") + nested_type_->GetName() + ")"; }
std::string GetName() const { return std::string("lowcardinality(") + nested_type_->GetName() + ")"; }

/// Type of nested nullable element.
TypeRef GetNestedType() const { return nested_type_; }
Expand Down
6 changes: 3 additions & 3 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using namespace clickhouse;
int main()
{
/// Initialize client connection.
Client client(ClientOptions().SetHost("localhost"));
Client client(ClientOptions().SetHost("localhost").SetPort(8463));

/// Create a table.
client.Execute("CREATE TABLE IF NOT EXISTS default.numbers (id UInt64, name String) ENGINE = Memory");
client.Execute("CREATE STREAM IF NOT EXISTS default.numbers (id uint64, name string) ENGINE = Memory");

/// Insert some values.
{
Expand Down Expand Up @@ -40,7 +40,7 @@ int main()
);

/// Delete table.
client.Execute("DROP TABLE default.numbers");
// client.Execute("DROP STREAM default.numbers");

return 0;
}

0 comments on commit 92eaa83

Please sign in to comment.