Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for DATE, TIME, DATETIME and TIMESTAMP #393

Merged
merged 12 commits into from
Dec 29, 2023
7 changes: 4 additions & 3 deletions scripts/Dockerfile_infinity_builder_centos7
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# NOTICE: This Dockerfile depends on BuildKit
# NOTICE: You should prepare the following files:
# NOTICE: You should prepare the following files
# NOTICE: You can use the download_deps_infinity_builder_centos7.sh script to download them
# bison-3.8.2.tar.xz
# binutils-2.41.tar.xz
# gcc-13.2.0.tar.xz
Expand Down Expand Up @@ -66,14 +67,14 @@ RUN --mount=type=bind,source=llvm-project-17.0.6.src.tar.xz,target=/root/llvm-pr
cd /root && tar xf llvm-project-17.0.6.src.tar.xz \
&& cd llvm-project-17.0.6.src && mkdir build && cd build \
&& cmake -G Ninja -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_JOB_POOL_LINK:STRING=link_pool \
-DCMAKE_JOB_POOLS:STRING=link_pool=1 \
-DCMAKE_JOB_POOL_LINK:STRING=link_pool \
-DGCC_INSTALL_PREFIX=/usr/local \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;lldb" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON \
-DLLVM_TARGETS_TO_BUILD=X86 ../llvm \
&& ninja -j6 install/strip \
&& ninja -j12 install/strip \
&& ldconfig && cd /root && rm -rf llvm-project-17.0.6.src

# Install boost-1.81.0
Expand Down
6 changes: 4 additions & 2 deletions scripts/infinity-deps-ubuntu2004.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e -o pipefail

echo
echo "running script $0"
echo "current working directory : $PWD"
Expand Down Expand Up @@ -37,10 +39,10 @@ unzip ninja-linux.zip && sudo cp ninja /usr/local/bin && rm ninja

echo
echo 'step [6/9] : add apt source for llvm-17'
echo 'command: sudo echo -e "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" > /etc/apt/sources.list.d/llvm17.list'
echo 'command: echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list'
echo 'command: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc'
echo
sudo echo -e "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" > /etc/apt/sources.list.d/llvm17.list
echo "deb https://apt.llvm.org/focal/ llvm-toolchain-focal-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc

echo
Expand Down
6 changes: 4 additions & 2 deletions scripts/infinity-deps-ubuntu2204.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e -o pipefail

echo
echo "running script $0"
echo "current working directory : $PWD"
Expand Down Expand Up @@ -37,10 +39,10 @@ unzip ninja-linux.zip && sudo cp ninja /usr/local/bin && rm ninja

echo
echo 'step [6/9] : add apt source for llvm-17'
echo 'command: sudo echo -e "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" > /etc/apt/sources.list.d/llvm17.list'
echo 'command: echo "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list'
echo 'command: wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc'
echo
sudo echo -e "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" > /etc/apt/sources.list.d/llvm17.list
echo "deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee /etc/apt/sources.list.d/llvm17.list
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc

echo
Expand Down
2 changes: 2 additions & 0 deletions scripts/infinity-deps-ubuntu2310.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -e -o pipefail

echo
echo "running script $0"
echo "current working directory : $PWD"
Expand Down
13 changes: 12 additions & 1 deletion src/executor/expression/expression_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,20 @@ SharedPtr<ExpressionState> ExpressionState::CreateState(const SharedPtr<Function
// }
// }
// }
bool result_is_constant = true;
for (auto &child_state : result->Children()) {
if (auto &column_ptr = child_state->OutputColumnVector(); !column_ptr || column_ptr->vector_type() != ColumnVectorType::kConstant) {
result_is_constant = false;
break;
}
}

result->column_vector_ = MakeShared<ColumnVector>(function_expr_data_type);
result->column_vector_->Initialize(ColumnVectorType::kFlat, DEFAULT_VECTOR_SIZE);
if (result_is_constant) {
result->column_vector_->Initialize(ColumnVectorType::kConstant, DEFAULT_VECTOR_SIZE);
} else {
result->column_vector_->Initialize(ColumnVectorType::kFlat, DEFAULT_VECTOR_SIZE);
}

// result->output_data_block_.Init({function_expr->Type()});
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/executor/operator/physical_show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ void PhysicalShow::ExecuteShowColumns(QueryContext *query_context, ShowOperatorS
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[column_id]);
}
output_block_ptr->Finalize();
}
output_block_ptr->Finalize();

show_operator_state->output_.emplace_back(Move(output_block_ptr));
}
Expand Down
36 changes: 29 additions & 7 deletions src/function/scalar/add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,22 @@ inline bool AddFunction::Run(IntervalT left, DateT right, DateT &result) {
return DateT::Add(right, left, result);
}

// Time + Interval
template <>
inline bool AddFunction::Run(TimeT left, IntervalT right, TimeT &result) {
return TimeT::Add(left, right, result);
}

// Interval + Time
template <>
inline bool AddFunction::Run(IntervalT left, TimeT right, TimeT &result) {
return TimeT::Add(right, left, result);
}

// DateTime + Interval
template <>
inline bool AddFunction::Run(DateTimeT, IntervalT, DateTimeT &) {
Error<NotImplementException>("Not implemented: DateTimeT + IntervalT");
return false;
inline bool AddFunction::Run(DateTimeT left, IntervalT right, DateTimeT &result) {
return DateTimeT::Add(left, right, result);
}

// Interval + DateTime
Expand All @@ -133,9 +144,8 @@ inline bool AddFunction::Run(IntervalT left, DateTimeT right, DateTimeT &result)

// TimestampT + Interval
template <>
inline bool AddFunction::Run(TimestampT, IntervalT, TimestampT &) {
Error<NotImplementException>("Not implemented: TimestampT + IntervalT");
return false;
inline bool AddFunction::Run(TimestampT left, IntervalT right, TimestampT &result) {
return TimestampT::Add(left, right, result);
}

// Interval + TimestampT
Expand Down Expand Up @@ -240,9 +250,21 @@ void RegisterAddFunction(const UniquePtr<NewCatalog> &catalog_ptr) {
ScalarFunction add_function_interval_date(func_name,
{DataType(LogicalType::kInterval), DataType(LogicalType::kDate)},
{DataType(LogicalType::kDate)},
&ScalarFunction::BinaryFunctionWithFailure<DateT, IntervalT, DateT, AddFunction>);
&ScalarFunction::BinaryFunctionWithFailure<IntervalT, DateT, DateT, AddFunction>);
function_set_ptr->AddFunction(add_function_interval_date);

ScalarFunction add_function_time_interval(func_name,
{DataType(LogicalType::kTime), DataType(LogicalType::kInterval)},
{DataType(LogicalType::kTime)},
&ScalarFunction::BinaryFunctionWithFailure<TimeT, IntervalT, TimeT, AddFunction>);
function_set_ptr->AddFunction(add_function_time_interval);

ScalarFunction add_function_interval_time(func_name,
{DataType(LogicalType::kInterval), DataType(LogicalType::kTime)},
{DataType(LogicalType::kTime)},
&ScalarFunction::BinaryFunctionWithFailure<IntervalT, TimeT, TimeT, AddFunction>);
function_set_ptr->AddFunction(add_function_interval_time);

ScalarFunction add_function_datetime_interval(func_name,
{DataType(LogicalType::kDateTime), DataType(LogicalType::kInterval)},
{DataType(LogicalType::kDateTime)},
Expand Down
6 changes: 3 additions & 3 deletions src/function/scalar/equals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ void RegisterEqualsFunction(const UniquePtr<NewCatalog> &catalog_ptr) {
// GenerateEqualsFunction<CharT>(function_set_ptr, DataType(LogicalType::kChar));

GenerateEqualsFunction<DateT>(function_set_ptr, DataType(LogicalType::kDate));
// GenerateEqualsFunction<TimeT>(function_set_ptr, DataType(LogicalType::kTime));
// GenerateEqualsFunction<DateTimeT>(function_set_ptr, DataType(LogicalType::kDateTime));
// GenerateEqualsFunction<TimestampT>(function_set_ptr, DataType(LogicalType::kTimestamp));
GenerateEqualsFunction<TimeT>(function_set_ptr, DataType(LogicalType::kTime));
GenerateEqualsFunction<DateTimeT>(function_set_ptr, DataType(LogicalType::kDateTime));
GenerateEqualsFunction<TimestampT>(function_set_ptr, DataType(LogicalType::kTimestamp));
// GenerateEqualsFunction<TimestampTZT>(function_set_ptr, DataType(LogicalType::kTimestampTZ));
// GenerateEqualsFunction<IntervalT>(function_set_ptr, DataType(LogicalType::kInterval));

Expand Down
Loading
Loading