diff --git a/AGENT.md b/AGENT.md new file mode 100644 index 00000000..0aab5eec --- /dev/null +++ b/AGENT.md @@ -0,0 +1,165 @@ +# KiteSQL Agent Guide + +This document defines the engineering principles, code style, and contribution expectations +for the KiteSQL project. + +KiteSQL is a lightweight, simple, low-dependency OLTP database. +All code contributions (human or AI-generated) must follow the rules below. + +--- + +## 1. Project Philosophy + +KiteSQL prioritizes: + +- Lightweight design +- Simple and explicit logic +- Low dependency footprint +- High correctness through testing +- Readable code over clever code + +This is an OLTP-oriented system. +Predictability, correctness, and maintainability are more important than micro-optimizations. + +--- + +## 2. Testing Requirements (MANDATORY) + +### 2.1 Makefile Is the Source of Truth + +All test commands must be defined and discoverable in the Makefile. + +This includes (but is not limited to): + +- Unit tests +- Integration tests +- SQL behavior tests +- Regression tests + +If a test cannot be triggered via make, it is considered incomplete. + +Examples: +``` +make test +make test-unit +make test-integration +``` + +PRs must not introduce hidden, ad-hoc, or undocumented test commands. + +--- + +### 2.2 Tests Are Not Optional + +- Every PR must include sufficient unit tests +- New functionality must be covered by tests +- Bug fixes must include regression tests + +If logic is complex, tests are preferred over comments. + +Untested code is considered incomplete code. + +--- + +### 2.3 Expand Test Coverage When Touching Code + +When modifying existing functionality, contributors are expected to: + +- Identify related edge cases or failure modes +- Add unit tests for behaviors that were previously untested +- Strengthen coverage around logic affected by the change + +This applies even if the original change request does not explicitly ask for new tests. + +If you are already touching the code, it is the best time to fix missing tests. + +PRs that modify logic but leave obvious test gaps untouched may be rejected. + +--- + +## 3. Code Simplicity Rules + +### 3.1 Prefer Simple Code + +- Prefer straightforward control flow +- Avoid unnecessary abstractions +- Avoid premature generalization +- Avoid clever tricks that reduce readability + +If something can be written clearly using fewer concepts, do that. + +--- + +### 3.2 Low Comments, High Signal + +- Do not comment obvious code +- Do not restate what the code already expresses +- Prefer self-explanatory naming + +However, the following must include short, precise comments: + +- Complex logic +- Non-obvious invariants +- Encoding, ordering, or correctness-sensitive behavior + +Comments should explain why, not what. + +Example: +```rust +// Keys are encoded in mem-comparable form to preserve lexicographical ordering +``` + +--- + +## 4. Code Reuse & Structure + +### 4.1 Reuse Over Duplication + +- Prefer extracting shared logic over copy-pasting +- Shared behavior should live in a single place +- Avoid near-duplicate implementations with small differences + +If code looks similar in multiple places, it probably wants to be reused. + +--- + +### 4.2 Minimal APIs + +- Public APIs should be minimal and intentional +- Avoid exposing internal details +- Keep modules small, focused, and cohesive + +--- + +## 5. Dependency Policy + +- Dependencies are costly +- Every new dependency must be justified +- Prefer standard library solutions where possible +- Avoid heavy frameworks or macro-heavy crates unless strictly necessary + +KiteSQL aims to stay easy to build, easy to audit, and easy to understand. + +--- + +## 6. PR Expectations + +A valid PR should: + +- Compile cleanly +- Pass all tests via make +- Include new tests if behavior changes +- Improve or extend test coverage when touching existing code +- Keep code simple and readable +- Reuse existing abstractions where possible +- Follow the spirit of KiteSQL: simple, lightweight, correct + +PRs that increase complexity without clear benefit may be rejected. + +--- + +## 7. Final Principle + +If the code is hard to understand, it is probably wrong. + +Clarity is a feature. diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..2a5fe433 --- /dev/null +++ b/Makefile @@ -0,0 +1,25 @@ +# Helper variables (override on invocation if needed). +CARGO ?= cargo +WASM_PACK ?= wasm-pack +SQLLOGIC_PATH ?= tests/slt/**/*.slt + +.PHONY: test test-wasm test-slt test-all wasm-build + +## Run default Rust tests in the current environment (non-WASM). +test: + $(CARGO) test + +## Build the WebAssembly package (artifact goes to ./pkg). +wasm-build: + $(WASM_PACK) build --release --target nodejs + +## Execute wasm-bindgen tests under Node.js (wasm32 target). +test-wasm: + $(WASM_PACK) test --node --release + +## Run the sqllogictest harness against the configured .slt suite. +test-slt: + $(CARGO) run -p sqllogictest-test -- --path $(SQLLOGIC_PATH) + +## Convenience target to run every suite in sequence. +test-all: test test-wasm test-slt diff --git a/benchmarks/query_benchmark.rs b/benchmarks/query_benchmark.rs index 339075fd..79093863 100644 --- a/benchmarks/query_benchmark.rs +++ b/benchmarks/query_benchmark.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use criterion::{criterion_group, criterion_main, Criterion}; use indicatif::{ProgressBar, ProgressStyle}; use kite_sql::db::{DataBaseBuilder, ResultIter}; diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 46b5a223..f0de3e76 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + #![cfg(not(target_arch = "wasm32"))] use kite_sql::db::{DataBaseBuilder, ResultIter}; diff --git a/examples/transaction.rs b/examples/transaction.rs index ff69b835..50d57f28 100644 --- a/examples/transaction.rs +++ b/examples/transaction.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + #![cfg(not(target_arch = "wasm32"))] use kite_sql::db::{DataBaseBuilder, ResultIter}; diff --git a/kite_sql_serde_macros/src/lib.rs b/kite_sql_serde_macros/src/lib.rs index 27dcec19..9f06b479 100644 --- a/kite_sql_serde_macros/src/lib.rs +++ b/kite_sql_serde_macros/src/lib.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + mod reference_serialization; use proc_macro::TokenStream; diff --git a/kite_sql_serde_macros/src/reference_serialization.rs b/kite_sql_serde_macros/src/reference_serialization.rs index 1da46649..2a688ed1 100644 --- a/kite_sql_serde_macros/src/reference_serialization.rs +++ b/kite_sql_serde_macros/src/reference_serialization.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use darling::ast::Data; use darling::{FromDeriveInput, FromField, FromVariant}; use proc_macro2::{Ident, Span, TokenStream}; diff --git a/src/bin/server.rs b/src/bin/server.rs index 222365a0..1e7edc38 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use async_trait::async_trait; use clap::Parser; use futures::stream; diff --git a/src/binder/aggregate.rs b/src/binder/aggregate.rs index b619bfd2..d9632afd 100644 --- a/src/binder/aggregate.rs +++ b/src/binder/aggregate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use ahash::RandomState; use itertools::Itertools; use sqlparser::ast::{Expr, OrderByExpr}; diff --git a/src/binder/alter_table.rs b/src/binder/alter_table.rs index 413abc6f..fb41e175 100644 --- a/src/binder/alter_table.rs +++ b/src/binder/alter_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use sqlparser::ast::{AlterTableOperation, ObjectName}; use std::sync::Arc; diff --git a/src/binder/analyze.rs b/src/binder/analyze.rs index 4eb06237..cd2747c7 100644 --- a/src/binder/analyze.rs +++ b/src/binder/analyze.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder, Source}; use crate::errors::DatabaseError; use crate::planner::operator::analyze::AnalyzeOperator; diff --git a/src/binder/copy.rs b/src/binder/copy.rs index 6e4be3e4..60fa5aed 100644 --- a/src/binder/copy.rs +++ b/src/binder/copy.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; diff --git a/src/binder/create_index.rs b/src/binder/create_index.rs index dce2b07f..03e87b46 100644 --- a/src/binder/create_index.rs +++ b/src/binder/create_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder, Source}; use crate::errors::DatabaseError; use crate::expression::ScalarExpression; diff --git a/src/binder/create_table.rs b/src/binder/create_table.rs index 5f71cfac..dc09b002 100644 --- a/src/binder/create_table.rs +++ b/src/binder/create_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::{is_valid_identifier, Binder}; use crate::binder::lower_case_name; use crate::catalog::{ColumnCatalog, ColumnDesc}; diff --git a/src/binder/create_view.rs b/src/binder/create_view.rs index dc162c4d..f8b32df7 100644 --- a/src/binder/create_view.rs +++ b/src/binder/create_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, lower_ident, Binder}; use crate::catalog::view::View; use crate::catalog::{ColumnCatalog, ColumnRef}; diff --git a/src/binder/delete.rs b/src/binder/delete.rs index 61e12fd2..b9fb3fd0 100644 --- a/src/binder/delete.rs +++ b/src/binder/delete.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder, Source}; use crate::errors::DatabaseError; use crate::planner::operator::delete::DeleteOperator; diff --git a/src/binder/describe.rs b/src/binder/describe.rs index d32809a8..efc80594 100644 --- a/src/binder/describe.rs +++ b/src/binder/describe.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::planner::operator::describe::DescribeOperator; diff --git a/src/binder/distinct.rs b/src/binder/distinct.rs index db431f2f..a4766148 100644 --- a/src/binder/distinct.rs +++ b/src/binder/distinct.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{Binder, QueryBindStep}; use crate::expression::ScalarExpression; use crate::planner::operator::aggregate::AggregateOperator; diff --git a/src/binder/drop_index.rs b/src/binder/drop_index.rs index 7d625c2e..1a2dd6f9 100644 --- a/src/binder/drop_index.rs +++ b/src/binder/drop_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_ident, Binder}; use crate::errors::DatabaseError; use crate::planner::operator::drop_index::DropIndexOperator; diff --git a/src/binder/drop_table.rs b/src/binder/drop_table.rs index 173c9cd2..ff0cbfa6 100644 --- a/src/binder/drop_table.rs +++ b/src/binder/drop_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::planner::operator::drop_table::DropTableOperator; diff --git a/src/binder/drop_view.rs b/src/binder/drop_view.rs index 9c32f84b..7e74e995 100644 --- a/src/binder/drop_view.rs +++ b/src/binder/drop_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::planner::operator::drop_view::DropViewOperator; diff --git a/src/binder/explain.rs b/src/binder/explain.rs index 1a0df211..5b363527 100644 --- a/src/binder/explain.rs +++ b/src/binder/explain.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::Binder; use crate::errors::DatabaseError; use crate::planner::operator::Operator; diff --git a/src/binder/expr.rs b/src/binder/expr.rs index 1c6ed721..360a9515 100644 --- a/src/binder/expr.rs +++ b/src/binder/expr.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, ColumnRef, TableName}; use crate::errors::DatabaseError; use crate::expression; diff --git a/src/binder/insert.rs b/src/binder/insert.rs index b9d718dc..cdd2ed8d 100644 --- a/src/binder/insert.rs +++ b/src/binder/insert.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::expression::simplify::ConstantCalculator; diff --git a/src/binder/mod.rs b/src/binder/mod.rs index 52216846..96bcf0c3 100644 --- a/src/binder/mod.rs +++ b/src/binder/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod aggregate; mod alter_table; mod analyze; diff --git a/src/binder/select.rs b/src/binder/select.rs index 40b7a63f..bd4bf4b6 100644 --- a/src/binder/select.rs +++ b/src/binder/select.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::{ expression::ScalarExpression, planner::{ diff --git a/src/binder/show_table.rs b/src/binder/show_table.rs index 04672df9..347fe2b9 100644 --- a/src/binder/show_table.rs +++ b/src/binder/show_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::Binder; use crate::errors::DatabaseError; use crate::planner::operator::Operator; diff --git a/src/binder/show_view.rs b/src/binder/show_view.rs index dbcc9b2c..63a81ed2 100644 --- a/src/binder/show_view.rs +++ b/src/binder/show_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::Binder; use crate::errors::DatabaseError; use crate::planner::operator::Operator; diff --git a/src/binder/truncate.rs b/src/binder/truncate.rs index 4a6beb84..222f8305 100644 --- a/src/binder/truncate.rs +++ b/src/binder/truncate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::planner::operator::truncate::TruncateOperator; diff --git a/src/binder/update.rs b/src/binder/update.rs index a6460e1d..d29b23a7 100644 --- a/src/binder/update.rs +++ b/src/binder/update.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{lower_case_name, Binder}; use crate::errors::DatabaseError; use crate::expression::ScalarExpression; diff --git a/src/catalog/column.rs b/src/catalog/column.rs index 08998613..a6988cba 100644 --- a/src/catalog/column.rs +++ b/src/catalog/column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::errors::DatabaseError; use crate::expression::ScalarExpression; diff --git a/src/catalog/mod.rs b/src/catalog/mod.rs index 5408fc1a..310ea673 100644 --- a/src/catalog/mod.rs +++ b/src/catalog/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + // Module: catalog pub(crate) use self::column::*; diff --git a/src/catalog/table.rs b/src/catalog/table.rs index e4181445..d5e3f05b 100644 --- a/src/catalog/table.rs +++ b/src/catalog/table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, ColumnRef, ColumnRelation}; use crate::errors::DatabaseError; use crate::types::index::{IndexMeta, IndexMetaRef, IndexType}; diff --git a/src/catalog/view.rs b/src/catalog/view.rs index a6800da4..3663a679 100644 --- a/src/catalog/view.rs +++ b/src/catalog/view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::planner::LogicalPlan; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/db.rs b/src/db.rs index 99833531..f0d6e771 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::{command_type, Binder, BinderContext, CommandType}; use crate::errors::DatabaseError; use crate::execution::{build_write, Executor}; diff --git a/src/errors.rs b/src/errors.rs index 42fbed53..ef4da5d3 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::{BinaryOperator, ScalarExpression, UnaryOperator}; use crate::types::tuple::TupleId; use crate::types::LogicalType; diff --git a/src/execution/ddl/add_column.rs b/src/execution/ddl/add_column.rs index 6de3e681..85038b05 100644 --- a/src/execution/ddl/add_column.rs +++ b/src/execution/ddl/add_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, WriteExecutor}; use crate::planner::LogicalPlan; diff --git a/src/execution/ddl/create_index.rs b/src/execution/ddl/create_index.rs index 0e8c47b5..ad21246c 100644 --- a/src/execution/ddl/create_index.rs +++ b/src/execution/ddl/create_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::projection::Projection; use crate::execution::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, WriteExecutor}; diff --git a/src/execution/ddl/create_table.rs b/src/execution/ddl/create_table.rs index 596e5d50..9b8695ac 100644 --- a/src/execution/ddl/create_table.rs +++ b/src/execution/ddl/create_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::create_table::CreateTableOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/ddl/create_view.rs b/src/execution/ddl/create_view.rs index 52afdcf7..ec1cf0e4 100644 --- a/src/execution/ddl/create_view.rs +++ b/src/execution/ddl/create_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::create_view::CreateViewOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/ddl/drop_column.rs b/src/execution/ddl/drop_column.rs index b27f4a29..32d40097 100644 --- a/src/execution/ddl/drop_column.rs +++ b/src/execution/ddl/drop_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::alter_table::drop_column::DropColumnOperator; diff --git a/src/execution/ddl/drop_index.rs b/src/execution/ddl/drop_index.rs index 826578ab..bfad0a13 100644 --- a/src/execution/ddl/drop_index.rs +++ b/src/execution/ddl/drop_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::drop_index::DropIndexOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/ddl/drop_table.rs b/src/execution/ddl/drop_table.rs index 524f1a44..36330258 100644 --- a/src/execution/ddl/drop_table.rs +++ b/src/execution/ddl/drop_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::drop_table::DropTableOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/ddl/drop_view.rs b/src/execution/ddl/drop_view.rs index 7932bc70..280715d3 100644 --- a/src/execution/ddl/drop_view.rs +++ b/src/execution/ddl/drop_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::drop_view::DropViewOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/ddl/mod.rs b/src/execution/ddl/mod.rs index 294c6c39..e19ebe7a 100644 --- a/src/execution/ddl/mod.rs +++ b/src/execution/ddl/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod add_column; pub(crate) mod create_index; pub(crate) mod create_table; diff --git a/src/execution/ddl/truncate.rs b/src/execution/ddl/truncate.rs index 02c942fc..29b7e61f 100644 --- a/src/execution/ddl/truncate.rs +++ b/src/execution/ddl/truncate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, WriteExecutor}; use crate::planner::operator::truncate::TruncateOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dml/analyze.rs b/src/execution/dml/analyze.rs index ce3a87fa..ae4d1109 100644 --- a/src/execution/dml/analyze.rs +++ b/src/execution/dml/analyze.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::errors::DatabaseError; use crate::execution::dql::projection::Projection; diff --git a/src/execution/dml/copy_from_file.rs b/src/execution/dml/copy_from_file.rs index 3831881c..4a9797a5 100644 --- a/src/execution/dml/copy_from_file.rs +++ b/src/execution/dml/copy_from_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::copy::FileFormat; use crate::catalog::PrimaryKeyIndices; use crate::errors::DatabaseError; diff --git a/src/execution/dml/copy_to_file.rs b/src/execution/dml/copy_to_file.rs index 6da4f9e4..ea6e3272 100644 --- a/src/execution/dml/copy_to_file.rs +++ b/src/execution/dml/copy_to_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::copy::FileFormat; use crate::errors::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; diff --git a/src/execution/dml/delete.rs b/src/execution/dml/delete.rs index 210a2247..35fd7e4a 100644 --- a/src/execution/dml/delete.rs +++ b/src/execution/dml/delete.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::errors::DatabaseError; use crate::execution::dql::projection::Projection; diff --git a/src/execution/dml/insert.rs b/src/execution/dml/insert.rs index 41a03b3e..6f244300 100644 --- a/src/execution/dml/insert.rs +++ b/src/execution/dml/insert.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, TableName}; use crate::errors::DatabaseError; use crate::execution::dql::projection::Projection; diff --git a/src/execution/dml/mod.rs b/src/execution/dml/mod.rs index 094edda3..69e64a46 100644 --- a/src/execution/dml/mod.rs +++ b/src/execution/dml/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod analyze; pub(crate) mod copy_from_file; pub(crate) mod copy_to_file; diff --git a/src/execution/dml/update.rs b/src/execution/dml/update.rs index 8c945779..c9114e7b 100644 --- a/src/execution/dml/update.rs +++ b/src/execution/dml/update.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnRef, TableName}; use crate::errors::DatabaseError; use crate::execution::dql::projection::Projection; diff --git a/src/execution/dql/aggregate/avg.rs b/src/execution/dql/aggregate/avg.rs index 019fda85..db10a202 100644 --- a/src/execution/dql/aggregate/avg.rs +++ b/src/execution/dql/aggregate/avg.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::aggregate::sum::SumAccumulator; use crate::execution::dql::aggregate::Accumulator; diff --git a/src/execution/dql/aggregate/count.rs b/src/execution/dql/aggregate/count.rs index 5daaae5a..8a18f2a2 100644 --- a/src/execution/dql/aggregate/count.rs +++ b/src/execution/dql/aggregate/count.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::aggregate::Accumulator; use crate::types::value::DataValue; diff --git a/src/execution/dql/aggregate/hash_agg.rs b/src/execution/dql/aggregate/hash_agg.rs index 7d5c745c..da24e7a9 100644 --- a/src/execution/dql/aggregate/hash_agg.rs +++ b/src/execution/dql/aggregate/hash_agg.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::aggregate::{create_accumulators, Accumulator}; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; diff --git a/src/execution/dql/aggregate/min_max.rs b/src/execution/dql/aggregate/min_max.rs index 35e8d02d..d2436570 100644 --- a/src/execution/dql/aggregate/min_max.rs +++ b/src/execution/dql/aggregate/min_max.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::aggregate::Accumulator; use crate::expression::BinaryOperator; diff --git a/src/execution/dql/aggregate/mod.rs b/src/execution/dql/aggregate/mod.rs index 5a3e64ce..72751731 100644 --- a/src/execution/dql/aggregate/mod.rs +++ b/src/execution/dql/aggregate/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + mod avg; mod count; pub mod hash_agg; diff --git a/src/execution/dql/aggregate/simple_agg.rs b/src/execution/dql/aggregate/simple_agg.rs index e9eb023c..c48aa0af 100644 --- a/src/execution/dql/aggregate/simple_agg.rs +++ b/src/execution/dql/aggregate/simple_agg.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::aggregate::create_accumulators; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::expression::ScalarExpression; diff --git a/src/execution/dql/aggregate/sum.rs b/src/execution/dql/aggregate/sum.rs index 14502dab..5d249b47 100644 --- a/src/execution/dql/aggregate/sum.rs +++ b/src/execution/dql/aggregate/sum.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::aggregate::Accumulator; use crate::expression::BinaryOperator; diff --git a/src/execution/dql/describe.rs b/src/execution/dql/describe.rs index 22ff4d6d..353833fc 100644 --- a/src/execution/dql/describe.rs +++ b/src/execution/dql/describe.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, TableName}; use crate::execution::DatabaseError; use crate::execution::{spawn_executor, Executor, ReadExecutor}; diff --git a/src/execution/dql/dummy.rs b/src/execution/dql/dummy.rs index 59733c0f..750d0097 100644 --- a/src/execution/dql/dummy.rs +++ b/src/execution/dql/dummy.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; use crate::types::tuple::Tuple; diff --git a/src/execution/dql/except.rs b/src/execution/dql/except.rs index 7c3bd044..7f07824e 100644 --- a/src/execution/dql/except.rs +++ b/src/execution/dql/except.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::planner::LogicalPlan; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/explain.rs b/src/execution/dql/explain.rs index c8dfd26e..aa1ad3a2 100644 --- a/src/execution/dql/explain.rs +++ b/src/execution/dql/explain.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::planner::LogicalPlan; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/filter.rs b/src/execution/dql/filter.rs index e235e5d1..d212807e 100644 --- a/src/execution/dql/filter.rs +++ b/src/execution/dql/filter.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::expression::ScalarExpression; use crate::planner::operator::filter::FilterOperator; diff --git a/src/execution/dql/function_scan.rs b/src/execution/dql/function_scan.rs index bc4db579..d3008b95 100644 --- a/src/execution/dql/function_scan.rs +++ b/src/execution/dql/function_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::expression::function::table::TableFunction; use crate::planner::operator::function_scan::FunctionScanOperator; diff --git a/src/execution/dql/index_scan.rs b/src/execution/dql/index_scan.rs index 773e6ece..16bb4bd3 100644 --- a/src/execution/dql/index_scan.rs +++ b/src/execution/dql/index_scan.rs @@ -1,18 +1,48 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::expression::range_detacher::Range; use crate::planner::operator::table_scan::TableScanOperator; use crate::storage::{Iter, StatisticsMetaCache, TableCache, Transaction, ViewCache}; use crate::throw; use crate::types::index::IndexMetaRef; +use crate::types::serialize::TupleValueSerializableImpl; pub(crate) struct IndexScan { op: TableScanOperator, index_by: IndexMetaRef, ranges: Vec, + covered_deserializers: Option>, } -impl From<(TableScanOperator, IndexMetaRef, Range)> for IndexScan { - fn from((op, index_by, range): (TableScanOperator, IndexMetaRef, Range)) -> Self { +impl + From<( + TableScanOperator, + IndexMetaRef, + Range, + Option>, + )> for IndexScan +{ + fn from( + (op, index_by, range, covered_deserializers): ( + TableScanOperator, + IndexMetaRef, + Range, + Option>, + ), + ) -> Self { let ranges = match range { Range::SortedRanges(ranges) => ranges, range => vec![range], @@ -22,6 +52,7 @@ impl From<(TableScanOperator, IndexMetaRef, Range)> for IndexScan { op, index_by, ranges, + covered_deserializers, } } } @@ -51,6 +82,7 @@ impl<'a, T: Transaction + 'a> ReadExecutor<'a, T> for IndexScan { self.index_by, self.ranges, with_pk, + self.covered_deserializers, ) ); diff --git a/src/execution/dql/join/hash/full_join.rs b/src/execution/dql/join/hash/full_join.rs index da5d1632..35cab767 100644 --- a/src/execution/dql/join/hash/full_join.rs +++ b/src/execution/dql/join/hash/full_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::dql::join::hash_join::BuildState; use crate::execution::dql::sort::BumpVec; diff --git a/src/execution/dql/join/hash/inner_join.rs b/src/execution/dql/join/hash/inner_join.rs index 5b12b7b6..183c90f6 100644 --- a/src/execution/dql/join/hash/inner_join.rs +++ b/src/execution/dql/join/hash/inner_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::{spawn_executor, Executor}; use crate::throw; diff --git a/src/execution/dql/join/hash/left_anti_join.rs b/src/execution/dql/join/hash/left_anti_join.rs index 1131d688..bf9ff524 100644 --- a/src/execution/dql/join/hash/left_anti_join.rs +++ b/src/execution/dql/join/hash/left_anti_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::left_semi_join::LeftSemiJoinState; use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::dql::join::hash_join::BuildState; diff --git a/src/execution/dql/join/hash/left_join.rs b/src/execution/dql/join/hash/left_join.rs index 5bb7f02f..bb4fc291 100644 --- a/src/execution/dql/join/hash/left_join.rs +++ b/src/execution/dql/join/hash/left_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::dql::join::hash_join::BuildState; use crate::execution::dql::sort::BumpVec; diff --git a/src/execution/dql/join/hash/left_semi_join.rs b/src/execution/dql/join/hash/left_semi_join.rs index 2c7be2cf..a60f4eca 100644 --- a/src/execution/dql/join/hash/left_semi_join.rs +++ b/src/execution/dql/join/hash/left_semi_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::dql::join::hash_join::BuildState; use crate::execution::dql::sort::BumpVec; diff --git a/src/execution/dql/join/hash/mod.rs b/src/execution/dql/join/hash/mod.rs index 16289d9f..85f2346b 100644 --- a/src/execution/dql/join/hash/mod.rs +++ b/src/execution/dql/join/hash/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod full_join; pub(crate) mod inner_join; pub(crate) mod left_anti_join; diff --git a/src/execution/dql/join/hash/right_join.rs b/src/execution/dql/join/hash/right_join.rs index 58048d06..c0d5d914 100644 --- a/src/execution/dql/join/hash/right_join.rs +++ b/src/execution/dql/join/hash/right_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::dql::join::hash::full_join::FullJoinState; use crate::execution::dql::join::hash::{filter, FilterArgs, JoinProbeState, ProbeArgs}; use crate::execution::{spawn_executor, Executor}; diff --git a/src/execution/dql/join/hash_join.rs b/src/execution/dql/join/hash_join.rs index 212d148d..3366c947 100644 --- a/src/execution/dql/join/hash_join.rs +++ b/src/execution/dql/join/hash_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::execution::dql::join::hash::full_join::FullJoinState; diff --git a/src/execution/dql/join/mod.rs b/src/execution/dql/join/mod.rs index 59ce4982..2ae7ffaa 100644 --- a/src/execution/dql/join/mod.rs +++ b/src/execution/dql/join/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::planner::operator::join::JoinType; mod hash; diff --git a/src/execution/dql/join/nested_loop_join.rs b/src/execution/dql/join/nested_loop_join.rs index 38588423..6991da32 100644 --- a/src/execution/dql/join/nested_loop_join.rs +++ b/src/execution/dql/join/nested_loop_join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + //! Defines the nested loop join executor, it supports [`JoinType::Inner`], [`JoinType::LeftOuter`], //! [`JoinType::LeftSemi`], [`JoinType::LeftAnti`], [`JoinType::RightOuter`], [`JoinType::Cross`], [`JoinType::Full`]. diff --git a/src/execution/dql/limit.rs b/src/execution/dql/limit.rs index f08b1702..aec7f045 100644 --- a/src/execution/dql/limit.rs +++ b/src/execution/dql/limit.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::planner::operator::limit::LimitOperator; use crate::planner::LogicalPlan; diff --git a/src/execution/dql/mod.rs b/src/execution/dql/mod.rs index 747da75f..67959f7f 100644 --- a/src/execution/dql/mod.rs +++ b/src/execution/dql/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod aggregate; pub(crate) mod describe; pub(crate) mod dummy; diff --git a/src/execution/dql/projection.rs b/src/execution/dql/projection.rs index 511ba8db..c5b9f49b 100644 --- a/src/execution/dql/projection.rs +++ b/src/execution/dql/projection.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; diff --git a/src/execution/dql/seq_scan.rs b/src/execution/dql/seq_scan.rs index 2158c69c..ca4aa5b2 100644 --- a/src/execution/dql/seq_scan.rs +++ b/src/execution/dql/seq_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::planner::operator::table_scan::TableScanOperator; use crate::storage::{Iter, StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/show_table.rs b/src/execution/dql/show_table.rs index fcc3adbb..be562a9c 100644 --- a/src/execution/dql/show_table.rs +++ b/src/execution/dql/show_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableMeta; use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/show_view.rs b/src/execution/dql/show_view.rs index 4442c0a5..df88e3c6 100644 --- a/src/execution/dql/show_view.rs +++ b/src/execution/dql/show_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::view::View; use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/sort.rs b/src/execution/dql/sort.rs index c89ba794..0668c07d 100644 --- a/src/execution/dql/sort.rs +++ b/src/execution/dql/sort.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::planner::operator::sort::{SortField, SortOperator}; @@ -183,13 +197,13 @@ impl SortBy { let mut key = BumpBytes::new_in(arena); expr.eval(Some((tuple, schema)))? - .memcomparable_encode(&mut key)?; - if !asc { - for byte in key.iter_mut() { + .memcomparable_encode_with_null_order(&mut key, *nulls_first)?; + + if !asc && key.len() > 1 { + for byte in key.iter_mut().skip(1) { *byte ^= 0xFF; } } - key.push(if *nulls_first { u8::MIN } else { u8::MAX }); full_key.extend(key); } sort_keys.put((i, full_key)) diff --git a/src/execution/dql/top_k.rs b/src/execution/dql/top_k.rs index c735fe31..cd86649e 100644 --- a/src/execution/dql/top_k.rs +++ b/src/execution/dql/top_k.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::sort::BumpVec; use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; @@ -48,13 +62,12 @@ fn top_sort<'a>( { let mut key = BumpBytes::new_in(arena); expr.eval(Some((&tuple, &**schema)))? - .memcomparable_encode(&mut key)?; - if !asc { - for byte in key.iter_mut() { + .memcomparable_encode_with_null_order(&mut key, *nulls_first)?; + if !asc && key.len() > 1 { + for byte in key.iter_mut().skip(1) { *byte ^= 0xFF; } } - key.push(if *nulls_first { u8::MIN } else { u8::MAX }); full_key.extend(key); } diff --git a/src/execution/dql/union.rs b/src/execution/dql/union.rs index 928b7da5..1b63522a 100644 --- a/src/execution/dql/union.rs +++ b/src/execution/dql/union.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{build_read, spawn_executor, Executor, ReadExecutor}; use crate::planner::LogicalPlan; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/dql/values.rs b/src/execution/dql/values.rs index 5049ac10..10f97cf2 100644 --- a/src/execution/dql/values.rs +++ b/src/execution/dql/values.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::execution::{spawn_executor, Executor, ReadExecutor}; use crate::planner::operator::values::ValuesOperator; use crate::storage::{StatisticsMetaCache, TableCache, Transaction, ViewCache}; diff --git a/src/execution/execute_macro.rs b/src/execution/execute_macro.rs index 03851315..2c6752eb 100644 --- a/src/execution/execute_macro.rs +++ b/src/execution/execute_macro.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + #[macro_export] macro_rules! throw { ($co:expr, $code:expr) => { diff --git a/src/execution/mod.rs b/src/execution/mod.rs index 1517722c..84569c92 100644 --- a/src/execution/mod.rs +++ b/src/execution/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod ddl; pub(crate) mod dml; pub(crate) mod dql; @@ -124,9 +138,11 @@ pub fn build_read<'a, T: Transaction + 'a>( if let Some(PhysicalOption::IndexScan(IndexInfo { meta, range: Some(range), + covered_deserializers, })) = plan.physical_option { - IndexScan::from((op, meta, range)).execute(cache, transaction) + IndexScan::from((op, meta, range, covered_deserializers)) + .execute(cache, transaction) } else { SeqScan::from(op).execute(cache, transaction) } diff --git a/src/expression/agg.rs b/src/expression/agg.rs index cf7b4744..fb45df4e 100644 --- a/src/expression/agg.rs +++ b/src/expression/agg.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use kite_sql_serde_macros::ReferenceSerialization; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ReferenceSerialization)] diff --git a/src/expression/evaluator.rs b/src/expression/evaluator.rs index 3ac9b536..6a99912a 100644 --- a/src/expression/evaluator.rs +++ b/src/expression/evaluator.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::ScalarFunction; diff --git a/src/expression/function/mod.rs b/src/expression/function/mod.rs index e9d1276f..e1c0c3ef 100644 --- a/src/expression/function/mod.rs +++ b/src/expression/function/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::LogicalType; use serde::{Deserialize, Serialize}; use std::sync::Arc; diff --git a/src/expression/function/scala.rs b/src/expression/function/scala.rs index 1fa4df46..d7261d09 100644 --- a/src/expression/function/scala.rs +++ b/src/expression/function/scala.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::FunctionSummary; diff --git a/src/expression/function/table.rs b/src/expression/function/table.rs index 54627d07..7fc1cd23 100644 --- a/src/expression/function/table.rs +++ b/src/expression/function/table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableCatalog; use crate::errors::DatabaseError; use crate::expression::function::FunctionSummary; diff --git a/src/expression/mod.rs b/src/expression/mod.rs index 70aa4c38..87712486 100644 --- a/src/expression/mod.rs +++ b/src/expression/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use self::agg::AggKind; use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRef, ColumnSummary}; use crate::errors::DatabaseError; diff --git a/src/expression/range_detacher.rs b/src/expression/range_detacher.rs index e815916a..0dffbbd9 100644 --- a/src/expression/range_detacher.rs +++ b/src/expression/range_detacher.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::{BinaryOperator, ScalarExpression}; diff --git a/src/expression/simplify.rs b/src/expression/simplify.rs index 40964768..1f28cadf 100644 --- a/src/expression/simplify.rs +++ b/src/expression/simplify.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::visitor_mut::{walk_mut_expr, VisitorMut}; diff --git a/src/expression/visitor.rs b/src/expression/visitor.rs index dce20196..b7a949f8 100644 --- a/src/expression/visitor.rs +++ b/src/expression/visitor.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::agg::AggKind; diff --git a/src/expression/visitor_mut.rs b/src/expression/visitor_mut.rs index dd998afa..87325600 100644 --- a/src/expression/visitor_mut.rs +++ b/src/expression/visitor_mut.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::agg::AggKind; diff --git a/src/function/char_length.rs b/src/function/char_length.rs index 2c3c9f75..1b65e9da 100644 --- a/src/function/char_length.rs +++ b/src/function/char_length.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/function/current_date.rs b/src/function/current_date.rs index 05bae5b8..98e57a9d 100644 --- a/src/function/current_date.rs +++ b/src/function/current_date.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/function/current_timestamp.rs b/src/function/current_timestamp.rs index 592ca047..cd1d1369 100644 --- a/src/function/current_timestamp.rs +++ b/src/function/current_timestamp.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/function/lower.rs b/src/function/lower.rs index b5659974..ffe7e5dc 100644 --- a/src/function/lower.rs +++ b/src/function/lower.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/function/mod.rs b/src/function/mod.rs index 0fadd0ca..8c72a95a 100644 --- a/src/function/mod.rs +++ b/src/function/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod char_length; pub(crate) mod current_date; pub(crate) mod current_timestamp; diff --git a/src/function/numbers.rs b/src/function/numbers.rs index 920a19e7..cf4a67fd 100644 --- a/src/function/numbers.rs +++ b/src/function/numbers.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnCatalog; use crate::catalog::ColumnDesc; use crate::catalog::TableCatalog; diff --git a/src/function/octet_length.rs b/src/function/octet_length.rs index fac19e44..355e4cd3 100644 --- a/src/function/octet_length.rs +++ b/src/function/octet_length.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/function/upper.rs b/src/function/upper.rs index b0018b9e..26986081 100644 --- a/src/function/upper.rs +++ b/src/function/upper.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::function::scala::FuncMonotonicity; diff --git a/src/lib.rs b/src/lib.rs index c0f1d235..bd36d60f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + //! KiteSQL is a high-performance SQL database //! that can be embedded in Rust code (based on RocksDB by default), //! making it possible to call SQL just like calling a function. diff --git a/src/macros/mod.rs b/src/macros/mod.rs index e4dd570d..ad7c6a41 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + /// # Examples /// /// ``` diff --git a/src/optimizer/core/cm_sketch.rs b/src/optimizer/core/cm_sketch.rs index 09d4bb6e..928d25a0 100644 --- a/src/optimizer/core/cm_sketch.rs +++ b/src/optimizer/core/cm_sketch.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::expression::range_detacher::Range; use crate::serdes::{ReferenceSerialization, ReferenceTables}; diff --git a/src/optimizer/core/histogram.rs b/src/optimizer/core/histogram.rs index fb322829..5d7eff19 100644 --- a/src/optimizer/core/histogram.rs +++ b/src/optimizer/core/histogram.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::execution::dql::sort::{radix_sort, BumpVec, NullableVec}; use crate::expression::range_detacher::Range; diff --git a/src/optimizer/core/memo.rs b/src/optimizer/core/memo.rs index 678a0dde..d95d45e3 100644 --- a/src/optimizer/core/memo.rs +++ b/src/optimizer/core/memo.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::pattern::PatternMatcher; use crate::optimizer::core::rule::{ImplementationRule, MatchPattern}; @@ -212,6 +226,7 @@ mod tests { max: Bound::Unbounded, } ])), + covered_deserializers: None, })) ); diff --git a/src/optimizer/core/mod.rs b/src/optimizer/core/mod.rs index c2f41b09..4be7d875 100644 --- a/src/optimizer/core/mod.rs +++ b/src/optimizer/core/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod cm_sketch; pub(crate) mod histogram; pub(crate) mod memo; diff --git a/src/optimizer/core/pattern.rs b/src/optimizer/core/pattern.rs index bd49c197..f7127dbc 100644 --- a/src/optimizer/core/pattern.rs +++ b/src/optimizer/core/pattern.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::planner::operator::Operator; #[allow(dead_code)] diff --git a/src/optimizer/core/rule.rs b/src/optimizer/core/rule.rs index 69883b64..a4e768f0 100644 --- a/src/optimizer/core/rule.rs +++ b/src/optimizer/core/rule.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::GroupExpression; use crate::optimizer::core::pattern::Pattern; diff --git a/src/optimizer/core/statistics_meta.rs b/src/optimizer/core/statistics_meta.rs index 2642df10..763ed7c1 100644 --- a/src/optimizer/core/statistics_meta.rs +++ b/src/optimizer/core/statistics_meta.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::errors::DatabaseError; use crate::expression::range_detacher::Range; diff --git a/src/optimizer/heuristic/batch.rs b/src/optimizer/heuristic/batch.rs index 85b92f17..46e0e556 100644 --- a/src/optimizer/heuristic/batch.rs +++ b/src/optimizer/heuristic/batch.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::optimizer::rule::normalization::NormalizationRuleImpl; /// A batch of rules. diff --git a/src/optimizer/heuristic/graph.rs b/src/optimizer/heuristic/graph.rs index ab4ba372..8a5a5f53 100644 --- a/src/optimizer/heuristic/graph.rs +++ b/src/optimizer/heuristic/graph.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::optimizer::core::memo::Memo; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; diff --git a/src/optimizer/heuristic/matcher.rs b/src/optimizer/heuristic/matcher.rs index f79cdfee..4d5abd54 100644 --- a/src/optimizer/heuristic/matcher.rs +++ b/src/optimizer/heuristic/matcher.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate, PatternMatcher}; use crate::optimizer::heuristic::graph::{HepGraph, HepNodeId}; diff --git a/src/optimizer/heuristic/mod.rs b/src/optimizer/heuristic/mod.rs index b9fd5abb..311098b6 100644 --- a/src/optimizer/heuristic/mod.rs +++ b/src/optimizer/heuristic/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod batch; pub(crate) mod graph; pub(crate) mod matcher; diff --git a/src/optimizer/heuristic/optimizer.rs b/src/optimizer/heuristic/optimizer.rs index 116d310e..4b978ca1 100644 --- a/src/optimizer/heuristic/optimizer.rs +++ b/src/optimizer/heuristic/optimizer.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::Memo; use crate::optimizer::core::pattern::PatternMatcher; diff --git a/src/optimizer/mod.rs b/src/optimizer/mod.rs index 0165dc25..225c5884 100644 --- a/src/optimizer/mod.rs +++ b/src/optimizer/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + /// The architecture and some components, /// such as (/core) are referenced from sqlrs pub mod core; diff --git a/src/optimizer/rule/implementation/ddl/add_column.rs b/src/optimizer/rule/implementation/ddl/add_column.rs index 5234f093..7416cb03 100644 --- a/src/optimizer/rule/implementation/ddl/add_column.rs +++ b/src/optimizer/rule/implementation/ddl/add_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/ddl/create_table.rs b/src/optimizer/rule/implementation/ddl/create_table.rs index 32c52e0f..db626e4e 100644 --- a/src/optimizer/rule/implementation/ddl/create_table.rs +++ b/src/optimizer/rule/implementation/ddl/create_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/ddl/drop_column.rs b/src/optimizer/rule/implementation/ddl/drop_column.rs index be1ab5c3..b5fc4b31 100644 --- a/src/optimizer/rule/implementation/ddl/drop_column.rs +++ b/src/optimizer/rule/implementation/ddl/drop_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/ddl/drop_table.rs b/src/optimizer/rule/implementation/ddl/drop_table.rs index bddbee02..8e1de948 100644 --- a/src/optimizer/rule/implementation/ddl/drop_table.rs +++ b/src/optimizer/rule/implementation/ddl/drop_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/ddl/mod.rs b/src/optimizer/rule/implementation/ddl/mod.rs index 3bb8295f..5c44e0d0 100644 --- a/src/optimizer/rule/implementation/ddl/mod.rs +++ b/src/optimizer/rule/implementation/ddl/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod add_column; pub(crate) mod create_table; pub(crate) mod drop_column; diff --git a/src/optimizer/rule/implementation/ddl/truncate.rs b/src/optimizer/rule/implementation/ddl/truncate.rs index f96ed4d4..cc82117c 100644 --- a/src/optimizer/rule/implementation/ddl/truncate.rs +++ b/src/optimizer/rule/implementation/ddl/truncate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/analyze.rs b/src/optimizer/rule/implementation/dml/analyze.rs index 5d1700fe..50d5063b 100644 --- a/src/optimizer/rule/implementation/dml/analyze.rs +++ b/src/optimizer/rule/implementation/dml/analyze.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/copy_from_file.rs b/src/optimizer/rule/implementation/dml/copy_from_file.rs index 4d026ed3..96c7f9a3 100644 --- a/src/optimizer/rule/implementation/dml/copy_from_file.rs +++ b/src/optimizer/rule/implementation/dml/copy_from_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/copy_to_file.rs b/src/optimizer/rule/implementation/dml/copy_to_file.rs index 178cdb4a..d743f4b4 100644 --- a/src/optimizer/rule/implementation/dml/copy_to_file.rs +++ b/src/optimizer/rule/implementation/dml/copy_to_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/delete.rs b/src/optimizer/rule/implementation/dml/delete.rs index 13b706d7..c3db1b41 100644 --- a/src/optimizer/rule/implementation/dml/delete.rs +++ b/src/optimizer/rule/implementation/dml/delete.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/insert.rs b/src/optimizer/rule/implementation/dml/insert.rs index fc34f3c9..68a247ff 100644 --- a/src/optimizer/rule/implementation/dml/insert.rs +++ b/src/optimizer/rule/implementation/dml/insert.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dml/mod.rs b/src/optimizer/rule/implementation/dml/mod.rs index 094edda3..69e64a46 100644 --- a/src/optimizer/rule/implementation/dml/mod.rs +++ b/src/optimizer/rule/implementation/dml/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod analyze; pub(crate) mod copy_from_file; pub(crate) mod copy_to_file; diff --git a/src/optimizer/rule/implementation/dml/update.rs b/src/optimizer/rule/implementation/dml/update.rs index 81d610c5..555000e7 100644 --- a/src/optimizer/rule/implementation/dml/update.rs +++ b/src/optimizer/rule/implementation/dml/update.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/aggregate.rs b/src/optimizer/rule/implementation/dql/aggregate.rs index 25e79d80..5eedab5c 100644 --- a/src/optimizer/rule/implementation/dql/aggregate.rs +++ b/src/optimizer/rule/implementation/dql/aggregate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/dummy.rs b/src/optimizer/rule/implementation/dql/dummy.rs index 8369ca08..321dfdd6 100644 --- a/src/optimizer/rule/implementation/dql/dummy.rs +++ b/src/optimizer/rule/implementation/dql/dummy.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/filter.rs b/src/optimizer/rule/implementation/dql/filter.rs index a2931d84..e999c7c8 100644 --- a/src/optimizer/rule/implementation/dql/filter.rs +++ b/src/optimizer/rule/implementation/dql/filter.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/function_scan.rs b/src/optimizer/rule/implementation/dql/function_scan.rs index 229110d2..0989973c 100644 --- a/src/optimizer/rule/implementation/dql/function_scan.rs +++ b/src/optimizer/rule/implementation/dql/function_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/join.rs b/src/optimizer/rule/implementation/dql/join.rs index f1c62154..1b0825f4 100644 --- a/src/optimizer/rule/implementation/dql/join.rs +++ b/src/optimizer/rule/implementation/dql/join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/limit.rs b/src/optimizer/rule/implementation/dql/limit.rs index 410990ad..c1fbb505 100644 --- a/src/optimizer/rule/implementation/dql/limit.rs +++ b/src/optimizer/rule/implementation/dql/limit.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/mod.rs b/src/optimizer/rule/implementation/dql/mod.rs index 2907c60f..967594aa 100644 --- a/src/optimizer/rule/implementation/dql/mod.rs +++ b/src/optimizer/rule/implementation/dql/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod aggregate; pub(crate) mod dummy; pub(crate) mod filter; diff --git a/src/optimizer/rule/implementation/dql/projection.rs b/src/optimizer/rule/implementation/dql/projection.rs index 856af173..43091489 100644 --- a/src/optimizer/rule/implementation/dql/projection.rs +++ b/src/optimizer/rule/implementation/dql/projection.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/sort.rs b/src/optimizer/rule/implementation/dql/sort.rs index ed489c49..eff4f5b9 100644 --- a/src/optimizer/rule/implementation/dql/sort.rs +++ b/src/optimizer/rule/implementation/dql/sort.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/table_scan.rs b/src/optimizer/rule/implementation/dql/table_scan.rs index edb1d28e..22457b23 100644 --- a/src/optimizer/rule/implementation/dql/table_scan.rs +++ b/src/optimizer/rule/implementation/dql/table_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; @@ -79,7 +93,9 @@ impl ImplementationRule for IndexScanImplementation { { let mut row_count = statistics_meta.collect_count(range)?; - if !matches!(index_info.meta.ty, IndexType::PrimaryKey { .. }) { + if index_info.covered_deserializers.is_none() + && !matches!(index_info.meta.ty, IndexType::PrimaryKey { .. }) + { // need to return table query(non-covering index) row_count *= 2; } diff --git a/src/optimizer/rule/implementation/dql/top_k.rs b/src/optimizer/rule/implementation/dql/top_k.rs index ddb2f8b8..d98497cf 100644 --- a/src/optimizer/rule/implementation/dql/top_k.rs +++ b/src/optimizer/rule/implementation/dql/top_k.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/dql/values.rs b/src/optimizer/rule/implementation/dql/values.rs index bd10902b..c3ae6edc 100644 --- a/src/optimizer/rule/implementation/dql/values.rs +++ b/src/optimizer/rule/implementation/dql/values.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::memo::{Expression, GroupExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/implementation/macros.rs b/src/optimizer/rule/implementation/macros.rs index d2803967..dd29d4d1 100644 --- a/src/optimizer/rule/implementation/macros.rs +++ b/src/optimizer/rule/implementation/macros.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + #[macro_export] macro_rules! single_mapping { ($ty:ty, $pattern:expr, $option:expr) => { diff --git a/src/optimizer/rule/implementation/mod.rs b/src/optimizer/rule/implementation/mod.rs index 09e63837..27793abd 100644 --- a/src/optimizer/rule/implementation/mod.rs +++ b/src/optimizer/rule/implementation/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod ddl; pub(crate) mod dml; pub(crate) mod dql; diff --git a/src/optimizer/rule/mod.rs b/src/optimizer/rule/mod.rs index d825195d..6a2e995c 100644 --- a/src/optimizer/rule/mod.rs +++ b/src/optimizer/rule/mod.rs @@ -1,2 +1,16 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod implementation; pub(crate) mod normalization; diff --git a/src/optimizer/rule/normalization/column_pruning.rs b/src/optimizer/rule/normalization/column_pruning.rs index d6087a97..803f974c 100644 --- a/src/optimizer/rule/normalization/column_pruning.rs +++ b/src/optimizer/rule/normalization/column_pruning.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnSummary; use crate::errors::DatabaseError; use crate::expression::agg::AggKind; diff --git a/src/optimizer/rule/normalization/combine_operators.rs b/src/optimizer/rule/normalization/combine_operators.rs index 6a7a91a1..d1f012c6 100644 --- a/src/optimizer/rule/normalization/combine_operators.rs +++ b/src/optimizer/rule/normalization/combine_operators.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::expression::{BinaryOperator, ScalarExpression}; use crate::optimizer::core::pattern::{Pattern, PatternChildrenPredicate}; diff --git a/src/optimizer/rule/normalization/compilation_in_advance.rs b/src/optimizer/rule/normalization/compilation_in_advance.rs index e0bffc54..93950112 100644 --- a/src/optimizer/rule/normalization/compilation_in_advance.rs +++ b/src/optimizer/rule/normalization/compilation_in_advance.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::expression::visitor_mut::VisitorMut; use crate::expression::{BindEvaluator, BindPosition, ScalarExpression}; diff --git a/src/optimizer/rule/normalization/mod.rs b/src/optimizer/rule/normalization/mod.rs index 9d09ecd6..59684a0a 100644 --- a/src/optimizer/rule/normalization/mod.rs +++ b/src/optimizer/rule/normalization/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::expression::ScalarExpression; use crate::optimizer::core::pattern::Pattern; diff --git a/src/optimizer/rule/normalization/pushdown_limit.rs b/src/optimizer/rule/normalization/pushdown_limit.rs index 30f703f6..ff3327d3 100644 --- a/src/optimizer/rule/normalization/pushdown_limit.rs +++ b/src/optimizer/rule/normalization/pushdown_limit.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::pattern::Pattern; use crate::optimizer::core::pattern::PatternChildrenPredicate; diff --git a/src/optimizer/rule/normalization/pushdown_predicates.rs b/src/optimizer/rule/normalization/pushdown_predicates.rs index b56948e8..f345059b 100644 --- a/src/optimizer/rule/normalization/pushdown_predicates.rs +++ b/src/optimizer/rule/normalization/pushdown_predicates.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::errors::DatabaseError; use crate::expression::range_detacher::{Range, RangeDetacher}; @@ -13,9 +27,9 @@ use crate::types::index::{IndexInfo, IndexMetaRef, IndexType}; use crate::types::value::DataValue; use crate::types::LogicalType; use itertools::Itertools; -use std::mem; use std::ops::Bound; use std::sync::LazyLock; +use std::{mem, slice}; static PUSH_PREDICATE_THROUGH_JOIN: LazyLock = LazyLock::new(|| Pattern { predicate: |op| matches!(op, Operator::Filter(_)), @@ -215,12 +229,17 @@ impl NormalizationRule for PushPredicateIntoScan { fn apply(&self, node_id: HepNodeId, graph: &mut HepGraph) -> Result<(), DatabaseError> { if let Operator::Filter(op) = graph.operator(node_id).clone() { if let Some(child_id) = graph.eldest_child_at(node_id) { - if let Operator::TableScan(child_op) = graph.operator_mut(child_id) { - //FIXME: now only support `unique` and `primary key` - for IndexInfo { meta, range } in &mut child_op.index_infos { + if let Operator::TableScan(scan_op) = graph.operator_mut(child_id) { + for IndexInfo { + meta, + range, + covered_deserializers, + } in &mut scan_op.index_infos + { if range.is_some() { continue; } + // range detach *range = match meta.ty { IndexType::PrimaryKey { is_multiple: false } | IndexType::Unique @@ -232,6 +251,28 @@ impl NormalizationRule for PushPredicateIntoScan { Self::composite_range(&op, meta)? } }; + // try index covered + let mut deserializers = Vec::with_capacity(meta.column_ids.len()); + let mut cover_count = 0; + let index_column_types = match &meta.value_ty { + LogicalType::Tuple(tys) => tys, + ty => slice::from_ref(ty), + }; + for (i, column_id) in meta.column_ids.iter().enumerate() { + for column in scan_op.columns.values() { + deserializers.push( + if column.id().map(|id| &id == column_id).unwrap_or(false) { + cover_count += 1; + column.datatype().serializable() + } else { + index_column_types[i].skip_serializable() + }, + ); + } + } + if cover_count == scan_op.columns.len() { + *covered_deserializers = Some(deserializers) + } } } } diff --git a/src/optimizer/rule/normalization/simplification.rs b/src/optimizer/rule/normalization/simplification.rs index 0d5a7a37..c2b34ff2 100644 --- a/src/optimizer/rule/normalization/simplification.rs +++ b/src/optimizer/rule/normalization/simplification.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::expression::simplify::{ConstantCalculator, Simplify}; use crate::expression::visitor_mut::VisitorMut; diff --git a/src/optimizer/rule/normalization/top_k.rs b/src/optimizer/rule/normalization/top_k.rs index 7950c498..12f97f57 100644 --- a/src/optimizer/rule/normalization/top_k.rs +++ b/src/optimizer/rule/normalization/top_k.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::optimizer::core::pattern::Pattern; use crate::optimizer::core::pattern::PatternChildrenPredicate; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 41b0d4c2..fe21de48 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use sqlparser::parser::ParserError; use sqlparser::{ast::Statement, dialect::PostgreSqlDialect, parser::Parser}; diff --git a/src/paths.rs b/src/paths.rs index b96b0670..66018a06 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use std::path::PathBuf; pub const STATISTICS_META_SUBDIR: &str = "kite_sql_statistics_metas"; diff --git a/src/planner/mod.rs b/src/planner/mod.rs index 0bc8da9e..4db30993 100644 --- a/src/planner/mod.rs +++ b/src/planner/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod operator; use crate::catalog::{ColumnCatalog, ColumnRef, TableName}; diff --git a/src/planner/operator/aggregate.rs b/src/planner/operator/aggregate.rs index 8024d3a8..c59c9142 100644 --- a/src/planner/operator/aggregate.rs +++ b/src/planner/operator/aggregate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::planner::{Childrens, LogicalPlan}; use crate::{expression::ScalarExpression, planner::operator::Operator}; use itertools::Itertools; diff --git a/src/planner/operator/alter_table/add_column.rs b/src/planner/operator/alter_table/add_column.rs index a03608f6..cedc65e7 100644 --- a/src/planner/operator/alter_table/add_column.rs +++ b/src/planner/operator/alter_table/add_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, TableName}; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/alter_table/drop_column.rs b/src/planner/operator/alter_table/drop_column.rs index a731a54f..c3019d62 100644 --- a/src/planner/operator/alter_table/drop_column.rs +++ b/src/planner/operator/alter_table/drop_column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/alter_table/mod.rs b/src/planner/operator/alter_table/mod.rs index 413c5a01..8e59211c 100644 --- a/src/planner/operator/alter_table/mod.rs +++ b/src/planner/operator/alter_table/mod.rs @@ -1,2 +1,16 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod add_column; pub mod drop_column; diff --git a/src/planner/operator/analyze.rs b/src/planner/operator/analyze.rs index cc37d4d4..7df23bbe 100644 --- a/src/planner/operator/analyze.rs +++ b/src/planner/operator/analyze.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::types::index::IndexMetaRef; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/copy_from_file.rs b/src/planner/operator/copy_from_file.rs index 3888d8b7..b15df3c4 100644 --- a/src/planner/operator/copy_from_file.rs +++ b/src/planner/operator/copy_from_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::copy::ExtSource; use crate::catalog::TableName; use crate::types::tuple::SchemaRef; diff --git a/src/planner/operator/copy_to_file.rs b/src/planner/operator/copy_to_file.rs index 3305318b..5e823e3e 100644 --- a/src/planner/operator/copy_to_file.rs +++ b/src/planner/operator/copy_to_file.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::binder::copy::ExtSource; use crate::types::tuple::SchemaRef; use itertools::Itertools; diff --git a/src/planner/operator/create_index.rs b/src/planner/operator/create_index.rs index bc95570c..8df010a6 100644 --- a/src/planner/operator/create_index.rs +++ b/src/planner/operator/create_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnRef, TableName}; use crate::types::index::IndexType; use itertools::Itertools; diff --git a/src/planner/operator/create_table.rs b/src/planner/operator/create_table.rs index 8e5a9f13..e6c79103 100644 --- a/src/planner/operator/create_table.rs +++ b/src/planner/operator/create_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, TableName}; use itertools::Itertools; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/create_view.rs b/src/planner/operator/create_view.rs index 896f6866..3c0d054a 100644 --- a/src/planner/operator/create_view.rs +++ b/src/planner/operator/create_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::view::View; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/delete.rs b/src/planner/operator/delete.rs index 49fda089..394c6206 100644 --- a/src/planner/operator/delete.rs +++ b/src/planner/operator/delete.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnRef, TableName}; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/describe.rs b/src/planner/operator/describe.rs index 1e0a1826..8f3cc664 100644 --- a/src/planner/operator/describe.rs +++ b/src/planner/operator/describe.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/drop_index.rs b/src/planner/operator/drop_index.rs index 695cd18f..658e2f24 100644 --- a/src/planner/operator/drop_index.rs +++ b/src/planner/operator/drop_index.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; diff --git a/src/planner/operator/drop_table.rs b/src/planner/operator/drop_table.rs index 43cbab89..50eb73dc 100644 --- a/src/planner/operator/drop_table.rs +++ b/src/planner/operator/drop_table.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/drop_view.rs b/src/planner/operator/drop_view.rs index b14b2aa8..d9d587e6 100644 --- a/src/planner/operator/drop_view.rs +++ b/src/planner/operator/drop_view.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/except.rs b/src/planner/operator/except.rs index da232a2f..8e5570ca 100644 --- a/src/planner/operator/except.rs +++ b/src/planner/operator/except.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::types::tuple::SchemaRef; diff --git a/src/planner/operator/filter.rs b/src/planner/operator/filter.rs index c78b7df9..85135184 100644 --- a/src/planner/operator/filter.rs +++ b/src/planner/operator/filter.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::ScalarExpression; use crate::planner::{Childrens, LogicalPlan}; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/function_scan.rs b/src/planner/operator/function_scan.rs index 693727e7..a1af066c 100644 --- a/src/planner/operator/function_scan.rs +++ b/src/planner/operator/function_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::function::table::TableFunction; use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; diff --git a/src/planner/operator/insert.rs b/src/planner/operator/insert.rs index 853b536f..48eedf5c 100644 --- a/src/planner/operator/insert.rs +++ b/src/planner/operator/insert.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/join.rs b/src/planner/operator/join.rs index 0007deb4..176d4133 100644 --- a/src/planner/operator/join.rs +++ b/src/planner/operator/join.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::Operator; use crate::expression::ScalarExpression; use crate::planner::{Childrens, LogicalPlan}; diff --git a/src/planner/operator/limit.rs b/src/planner/operator/limit.rs index 5f78f492..e4a26d9c 100644 --- a/src/planner/operator/limit.rs +++ b/src/planner/operator/limit.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::Operator; use crate::planner::{Childrens, LogicalPlan}; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/mod.rs b/src/planner/operator/mod.rs index 90c1c7a9..d109dcba 100644 --- a/src/planner/operator/mod.rs +++ b/src/planner/operator/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod aggregate; pub mod alter_table; pub mod analyze; diff --git a/src/planner/operator/project.rs b/src/planner/operator/project.rs index 79e28a3b..003614b8 100644 --- a/src/planner/operator/project.rs +++ b/src/planner/operator/project.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::ScalarExpression; use itertools::Itertools; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/sort.rs b/src/planner/operator/sort.rs index 95774898..720f0e7e 100644 --- a/src/planner/operator/sort.rs +++ b/src/planner/operator/sort.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::ScalarExpression; use itertools::Itertools; use kite_sql_serde_macros::ReferenceSerialization; diff --git a/src/planner/operator/table_scan.rs b/src/planner/operator/table_scan.rs index f93eb521..29078ff7 100644 --- a/src/planner/operator/table_scan.rs +++ b/src/planner/operator/table_scan.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::Operator; use crate::catalog::{ColumnRef, TableCatalog, TableName}; use crate::planner::{Childrens, LogicalPlan}; @@ -48,6 +62,7 @@ impl TableScanOperator { .map(|meta| IndexInfo { meta: meta.clone(), range: None, + covered_deserializers: None, }) .collect_vec(); diff --git a/src/planner/operator/top_k.rs b/src/planner/operator/top_k.rs index 3772496f..d1037400 100644 --- a/src/planner/operator/top_k.rs +++ b/src/planner/operator/top_k.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::Operator; use crate::planner::operator::sort::SortField; use crate::planner::{Childrens, LogicalPlan}; diff --git a/src/planner/operator/truncate.rs b/src/planner/operator/truncate.rs index bc2f3370..1d0a105f 100644 --- a/src/planner/operator/truncate.rs +++ b/src/planner/operator/truncate.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::TableName; use kite_sql_serde_macros::ReferenceSerialization; use std::fmt; diff --git a/src/planner/operator/union.rs b/src/planner/operator/union.rs index 9b2c36e4..a196e796 100644 --- a/src/planner/operator/union.rs +++ b/src/planner/operator/union.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::planner::operator::Operator; use crate::planner::{Childrens, LogicalPlan}; use crate::types::tuple::SchemaRef; diff --git a/src/planner/operator/update.rs b/src/planner/operator/update.rs index 775273a0..2c767299 100644 --- a/src/planner/operator/update.rs +++ b/src/planner/operator/update.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnRef, TableName}; use crate::expression::ScalarExpression; use itertools::Itertools; diff --git a/src/planner/operator/values.rs b/src/planner/operator/values.rs index 55fafd4b..624554b6 100644 --- a/src/planner/operator/values.rs +++ b/src/planner/operator/values.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::tuple::SchemaRef; use crate::types::value::DataValue; use itertools::Itertools; diff --git a/src/serdes/boolean.rs b/src/serdes/boolean.rs index 6ec64ea0..5ddc4b2b 100644 --- a/src/serdes/boolean.rs +++ b/src/serdes/boolean.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/bound.rs b/src/serdes/bound.rs index 935836e3..82a9f137 100644 --- a/src/serdes/bound.rs +++ b/src/serdes/bound.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/btree_map.rs b/src/serdes/btree_map.rs index 6e0678e2..df3e4d54 100644 --- a/src/serdes/btree_map.rs +++ b/src/serdes/btree_map.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/char.rs b/src/serdes/char.rs index f853d001..f126cfbd 100644 --- a/src/serdes/char.rs +++ b/src/serdes/char.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/char_length_units.rs b/src/serdes/char_length_units.rs index 5adefdd6..f09e8e9c 100644 --- a/src/serdes/char_length_units.rs +++ b/src/serdes/char_length_units.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/column.rs b/src/serdes/column.rs index bff5f597..a8ccfd1c 100644 --- a/src/serdes/column.rs +++ b/src/serdes/column.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRef, ColumnRelation, ColumnSummary}; use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; diff --git a/src/serdes/data_value.rs b/src/serdes/data_value.rs index 38b1500a..1ea45dba 100644 --- a/src/serdes/data_value.rs +++ b/src/serdes/data_value.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::implement_serialization_by_bincode; use crate::types::value::DataValue; diff --git a/src/serdes/evaluator.rs b/src/serdes/evaluator.rs index 25622378..56acb932 100644 --- a/src/serdes/evaluator.rs +++ b/src/serdes/evaluator.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::implement_serialization_by_bincode; use crate::types::evaluator::{BinaryEvaluatorBox, UnaryEvaluatorBox}; diff --git a/src/serdes/function.rs b/src/serdes/function.rs index 6c56f724..c38ee206 100644 --- a/src/serdes/function.rs +++ b/src/serdes/function.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::expression::function::scala::ArcScalarFunctionImpl; use crate::expression::function::table::ArcTableFunctionImpl; use crate::implement_serialization_by_bincode; diff --git a/src/serdes/hasher.rs b/src/serdes/hasher.rs index 9f8535c5..0fe0da55 100644 --- a/src/serdes/hasher.rs +++ b/src/serdes/hasher.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::implement_serialization_by_bincode; use crate::optimizer::core::cm_sketch::FastHasher; diff --git a/src/serdes/mod.rs b/src/serdes/mod.rs index 9113e14f..e0db3192 100644 --- a/src/serdes/mod.rs +++ b/src/serdes/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + mod boolean; mod bound; mod btree_map; diff --git a/src/serdes/num.rs b/src/serdes/num.rs index e59f1417..9e8a86fb 100644 --- a/src/serdes/num.rs +++ b/src/serdes/num.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/option.rs b/src/serdes/option.rs index 866188c8..6b8ece88 100644 --- a/src/serdes/option.rs +++ b/src/serdes/option.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/pair.rs b/src/serdes/pair.rs index 3961b0b7..b90aacd3 100644 --- a/src/serdes/pair.rs +++ b/src/serdes/pair.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/path_buf.rs b/src/serdes/path_buf.rs index 3aae683a..aba7b38e 100644 --- a/src/serdes/path_buf.rs +++ b/src/serdes/path_buf.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::implement_serialization_by_bincode; use std::path::PathBuf; diff --git a/src/serdes/phantom.rs b/src/serdes/phantom.rs index 2f43410e..a642687d 100644 --- a/src/serdes/phantom.rs +++ b/src/serdes/phantom.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/ptr.rs b/src/serdes/ptr.rs index 399b7218..4a437795 100644 --- a/src/serdes/ptr.rs +++ b/src/serdes/ptr.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::serdes::DatabaseError; use crate::serdes::TableCache; use crate::serdes::Transaction; diff --git a/src/serdes/slice.rs b/src/serdes/slice.rs index b815e1cd..602eadb1 100644 --- a/src/serdes/slice.rs +++ b/src/serdes/slice.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/string.rs b/src/serdes/string.rs index 1530ccf8..3d221bfd 100644 --- a/src/serdes/string.rs +++ b/src/serdes/string.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::implement_serialization_by_bincode; use crate::serdes::{ReferenceSerialization, ReferenceTables}; diff --git a/src/serdes/trim.rs b/src/serdes/trim.rs index 0fdb2c2c..de6b26f3 100644 --- a/src/serdes/trim.rs +++ b/src/serdes/trim.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/ulid.rs b/src/serdes/ulid.rs index c55691d7..d56f93ba 100644 --- a/src/serdes/ulid.rs +++ b/src/serdes/ulid.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/serdes/vec.rs b/src/serdes/vec.rs index 15629a55..3f321d46 100644 --- a/src/serdes/vec.rs +++ b/src/serdes/vec.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; use crate::storage::{TableCache, Transaction}; diff --git a/src/storage/memory.rs b/src/storage/memory.rs index 9056eba6..a7ade776 100644 --- a/src/storage/memory.rs +++ b/src/storage/memory.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::storage::table_codec::{BumpBytes, Bytes, TableCodec}; use crate::storage::{InnerIter, Storage, Transaction}; @@ -218,6 +232,7 @@ mod wasm_tests { max: Bound::Included(DataValue::Int32(2)), }], true, + None, )?; let mut result = Vec::new(); @@ -349,6 +364,7 @@ mod native_tests { max: Bound::Included(DataValue::Int32(2)), }], true, + None, )?; let mut result = Vec::new(); diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 1d89d899..4b97b3be 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod memory; #[cfg(not(target_arch = "wasm32"))] pub mod rocksdb; @@ -99,8 +113,10 @@ pub trait Transaction: Sized { index_meta: IndexMetaRef, ranges: Vec, with_pk: bool, + covered_deserializers: Option>, ) -> Result, DatabaseError> { debug_assert!(columns.keys().all_unique()); + let values_len = columns.len(); let table = self .table(table_cache, table_name.clone())? @@ -113,9 +129,22 @@ pub trait Transaction: Sized { columns.insert(*i, column.clone()); } } - let (deserializers, remap_pk_indices) = - Self::create_deserializers(&columns, table, with_pk); - let inner = IndexImplEnum::instance(index_meta.ty); + let (inner, deserializers, remap_pk_indices) = + if let Some(deserializers) = covered_deserializers { + ( + IndexImplEnum::Covered(CoveredIndexImpl), + deserializers, + PrimaryKeyRemap::Covered, + ) + } else { + let (deserializers, remap_pk_indices) = + Self::create_deserializers(&columns, table, with_pk); + ( + IndexImplEnum::instance(index_meta.ty), + deserializers, + remap_pk_indices, + ) + }; Ok(IndexIter { offset, @@ -125,7 +154,7 @@ pub trait Transaction: Sized { index_meta, table_name, deserializers, - values_len: columns.len(), + values_len, total_len: table.columns_len(), tx: self, }, @@ -139,7 +168,7 @@ pub trait Transaction: Sized { columns: &BTreeMap, table: &TableCatalog, with_pk: bool, - ) -> (Vec, Option>) { + ) -> (Vec, PrimaryKeyRemap) { let primary_keys_indices = table.primary_keys_indices(); let mut deserializers = Vec::with_capacity(columns.len()); @@ -162,13 +191,17 @@ pub trait Transaction: Sized { deserializers.push(column.datatype().serializable()); last_projection = Some(*projection); } - let remap_pk_indices = with_pk.then(|| { - primary_keys_indices - .iter() - .filter_map(|pk| projections.binary_search(pk).ok()) - .collect_vec() - }); - (deserializers, remap_pk_indices) + let remap_pk = if with_pk { + PrimaryKeyRemap::Indices( + primary_keys_indices + .iter() + .filter_map(|pk| projections.binary_search(pk).ok()) + .collect_vec(), + ) + } else { + PrimaryKeyRemap::None + }; + (deserializers, remap_pk) } fn add_index_meta( @@ -457,10 +490,8 @@ pub trait Transaction: Sized { } }; match index_meta.ty { - IndexType::PrimaryKey { .. } | IndexType::Unique => { - return Err(DatabaseError::InvalidIndex) - } - IndexType::Normal | IndexType::Composite => (), + IndexType::PrimaryKey { .. } => return Err(DatabaseError::InvalidIndex), + IndexType::Unique | IndexType::Normal | IndexType::Composite => (), } let index_id = index_meta.id; @@ -758,15 +789,16 @@ pub trait Transaction: Sized { trait IndexImpl<'bytes, T: Transaction + 'bytes> { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + key: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result; fn eq_to_res<'a>( &self, value: &DataValue, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError>; @@ -783,6 +815,7 @@ enum IndexImplEnum { Unique(UniqueIndexImpl), Normal(NormalIndexImpl), Composite(CompositeIndexImpl), + Covered(CoveredIndexImpl), } impl IndexImplEnum { @@ -800,6 +833,7 @@ struct PrimaryKeyIndexImpl; struct UniqueIndexImpl; struct NormalIndexImpl; struct CompositeIndexImpl; +struct CoveredIndexImpl; struct IndexImplParams<'a, T: Transaction> { index_meta: IndexMetaRef, @@ -832,7 +866,7 @@ impl IndexImplParams<'_, T> { fn get_tuple_by_id( &self, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, tuple_id: &TupleId, ) -> Result, DatabaseError> { let key = unsafe { &*self.table_codec() }.encode_tuple_key(self.table_name, tuple_id)?; @@ -860,22 +894,24 @@ enum IndexResult<'a, T: Transaction + 'a> { impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for IndexImplEnum { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + key: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { match self { - IndexImplEnum::PrimaryKey(inner) => inner.index_lookup(bytes, pk_indices, params), - IndexImplEnum::Unique(inner) => inner.index_lookup(bytes, pk_indices, params), - IndexImplEnum::Normal(inner) => inner.index_lookup(bytes, pk_indices, params), - IndexImplEnum::Composite(inner) => inner.index_lookup(bytes, pk_indices, params), + IndexImplEnum::PrimaryKey(inner) => inner.index_lookup(key, value, pk_indices, params), + IndexImplEnum::Unique(inner) => inner.index_lookup(key, value, pk_indices, params), + IndexImplEnum::Normal(inner) => inner.index_lookup(key, value, pk_indices, params), + IndexImplEnum::Composite(inner) => inner.index_lookup(key, value, pk_indices, params), + IndexImplEnum::Covered(inner) => inner.index_lookup(key, value, pk_indices, params), } } fn eq_to_res<'a>( &self, value: &DataValue, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError> { match self { @@ -883,6 +919,7 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for IndexImplEnum { IndexImplEnum::Unique(inner) => inner.eq_to_res(value, pk_indices, params), IndexImplEnum::Normal(inner) => inner.eq_to_res(value, pk_indices, params), IndexImplEnum::Composite(inner) => inner.eq_to_res(value, pk_indices, params), + IndexImplEnum::Covered(inner) => inner.eq_to_res(value, pk_indices, params), } } @@ -897,6 +934,7 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for IndexImplEnum { IndexImplEnum::Unique(inner) => inner.bound_key(params, value, is_upper), IndexImplEnum::Normal(inner) => inner.bound_key(params, value, is_upper), IndexImplEnum::Composite(inner) => inner.bound_key(params, value, is_upper), + IndexImplEnum::Covered(inner) => inner.bound_key(params, value, is_upper), } } } @@ -904,14 +942,15 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for IndexImplEnum { impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for PrimaryKeyIndexImpl { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + _: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { TableCodec::decode_tuple( ¶ms.deserializers, pk_indices, - bytes, + value, params.values_len, params.total_len, ) @@ -920,7 +959,7 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for PrimaryKeyIndexIm fn eq_to_res<'a>( &self, value: &DataValue, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError> { let tuple = params @@ -949,9 +988,10 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for PrimaryKeyIndexIm } } +#[inline(always)] fn secondary_index_lookup( bytes: &Bytes, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { let tuple_id = TableCodec::decode_index(bytes)?; @@ -963,17 +1003,18 @@ fn secondary_index_lookup( impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for UniqueIndexImpl { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + _: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { - secondary_index_lookup(bytes, pk_indices, params) + secondary_index_lookup(value, pk_indices, params) } fn eq_to_res<'a>( &self, value: &DataValue, - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError> { let Some(bytes) = params.tx.get(&self.bound_key(params, value, false)?)? else { @@ -1001,26 +1042,21 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for UniqueIndexImpl { impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for NormalIndexImpl { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + _: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { - secondary_index_lookup(bytes, pk_indices, params) + secondary_index_lookup(value, pk_indices, params) } fn eq_to_res<'a>( &self, value: &DataValue, - _: Option<&[usize]>, + _: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError> { - let min = self.bound_key(params, value, false)?; - let max = self.bound_key(params, value, true)?; - - let iter = params - .tx - .range(Bound::Included(min), Bound::Included(max))?; - Ok(IndexResult::Scope(iter)) + eq_to_res_scope(self, value, params) } fn bound_key( @@ -1042,26 +1078,21 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for NormalIndexImpl { impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for CompositeIndexImpl { fn index_lookup( &self, - bytes: &Bytes, - pk_indices: Option<&[usize]>, + _: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, params: &IndexImplParams, ) -> Result { - secondary_index_lookup(bytes, pk_indices, params) + secondary_index_lookup(value, pk_indices, params) } fn eq_to_res<'a>( &self, value: &DataValue, - _: Option<&[usize]>, + _: &PrimaryKeyRemap, params: &IndexImplParams<'a, T>, ) -> Result, DatabaseError> { - let min = self.bound_key(params, value, false)?; - let max = self.bound_key(params, value, true)?; - - let iter = params - .tx - .range(Bound::Included(min), Bound::Included(max))?; - Ok(IndexResult::Scope(iter)) + eq_to_res_scope(self, value, params) } fn bound_key( @@ -1080,10 +1111,73 @@ impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for CompositeIndexImp } } +impl<'bytes, T: Transaction + 'bytes> IndexImpl<'bytes, T> for CoveredIndexImpl { + fn index_lookup( + &self, + key: &Bytes, + value: &Bytes, + pk_indices: &PrimaryKeyRemap, + params: &IndexImplParams, + ) -> Result { + let key = TableCodec::decode_index_key(key, params.value_ty())?; + + let mut tuple_id = None; + if matches!(pk_indices, PrimaryKeyRemap::Covered) { + tuple_id = Some(TableCodec::decode_index(value)?); + } + let values = match key { + DataValue::Tuple(vals, _) => vals, + v => { + vec![v] + } + }; + Ok(Tuple::new(tuple_id, values)) + } + + fn eq_to_res<'a>( + &self, + value: &DataValue, + _: &PrimaryKeyRemap, + params: &IndexImplParams<'a, T>, + ) -> Result, DatabaseError> { + eq_to_res_scope(self, value, params) + } + + fn bound_key( + &self, + params: &IndexImplParams, + value: &DataValue, + is_upper: bool, + ) -> Result, DatabaseError> { + let index = Index::new(params.index_meta.id, value, params.index_meta.ty); + + unsafe { &*params.table_codec() }.encode_index_bound_key( + params.table_name, + &index, + is_upper, + ) + } +} + +#[inline(always)] +fn eq_to_res_scope<'a, T: Transaction + 'a>( + index_impl: &impl IndexImpl<'a, T>, + value: &DataValue, + params: &IndexImplParams<'a, T>, +) -> Result, DatabaseError> { + let min = index_impl.bound_key(params, value, false)?; + let max = index_impl.bound_key(params, value, true)?; + + let iter = params + .tx + .range(Bound::Included(min), Bound::Included(max))?; + Ok(IndexResult::Scope(iter)) +} + pub struct TupleIter<'a, T: Transaction + 'a> { offset: usize, limit: Option, - remap_pk_indices: Option>, + remap_pk_indices: PrimaryKeyRemap, deserializers: Vec, values_len: usize, total_len: usize, @@ -1109,7 +1203,7 @@ impl<'a, T: Transaction + 'a> Iter for TupleIter<'a, T> { } let tuple = TableCodec::decode_tuple( &self.deserializers, - self.remap_pk_indices.as_deref(), + &self.remap_pk_indices, &value, self.values_len, self.total_len, @@ -1122,11 +1216,17 @@ impl<'a, T: Transaction + 'a> Iter for TupleIter<'a, T> { } } +pub enum PrimaryKeyRemap { + None, + Covered, + Indices(Vec), +} + pub struct IndexIter<'a, T: Transaction> { offset: usize, limit: Option, - remap_pk_indices: Option>, + remap_pk_indices: PrimaryKeyRemap, params: IndexImplParams<'a, T>, inner: IndexImplEnum, // for buffering data @@ -1230,7 +1330,7 @@ impl Iter for IndexIter<'_, T> { match self.inner.eq_to_res( &val, - self.remap_pk_indices.as_deref(), + &self.remap_pk_indices, &self.params, )? { IndexResult::Tuple(tuple) => { @@ -1249,14 +1349,15 @@ impl Iter for IndexIter<'_, T> { } } IndexIterState::Range(iter) => { - while let Some((_, bytes)) = iter.try_next()? { + while let Some((key, value)) = iter.try_next()? { if Self::offset_move(&mut self.offset) { continue; } Self::limit_sub(&mut self.limit); let tuple = self.inner.index_lookup( - &bytes, - self.remap_pk_indices.as_deref(), + &key, + &value, + &self.remap_pk_indices, &self.params, )?; @@ -1667,6 +1768,7 @@ mod test { max: Bound::Unbounded, }], true, + None, ) } diff --git a/src/storage/rocksdb.rs b/src/storage/rocksdb.rs index c705d763..31598340 100644 --- a/src/storage/rocksdb.rs +++ b/src/storage/rocksdb.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::storage::table_codec::{BumpBytes, Bytes, TableCodec}; use crate::storage::{InnerIter, Storage, Transaction}; @@ -230,7 +244,7 @@ mod test { use crate::storage::rocksdb::RocksStorage; use crate::storage::{ IndexImplEnum, IndexImplParams, IndexIter, IndexIterState, Iter, PrimaryKeyIndexImpl, - Storage, Transaction, + PrimaryKeyRemap, Storage, Transaction, }; use crate::types::index::{IndexMeta, IndexType}; use crate::types::tuple::Tuple; @@ -358,7 +372,7 @@ mod test { let mut iter = IndexIter { offset: 0, limit: None, - remap_pk_indices: Some(vec![0]), + remap_pk_indices: PrimaryKeyRemap::Indices(vec![0]), params: IndexImplParams { deserializers, index_meta: Arc::new(IndexMeta { @@ -426,6 +440,7 @@ mod test { max: Bound::Unbounded, }], true, + None, ) .unwrap(); @@ -451,6 +466,7 @@ mod test { max: Bound::Unbounded, }], true, + None, ) .unwrap(); @@ -462,4 +478,63 @@ mod test { Ok(()) } + + #[test] + fn test_read_by_index_cover() -> Result<(), DatabaseError> { + let temp_dir = TempDir::new().expect("unable to create temporary working directory"); + let kite_sql = DataBaseBuilder::path(temp_dir.path()).build()?; + kite_sql + .run("create table t1 (a int primary key, b int unique)")? + .done()?; + kite_sql + .run("insert into t1 (a, b) values (0, 0), (1, 1), (2, 2), (3, 4)")? + .done()?; + + let mut transaction = kite_sql.storage.transaction().unwrap(); + let table = transaction + .table(kite_sql.state.table_cache(), "t1".to_string().into())? + .unwrap() + .clone(); + let unique_index = table + .indexes + .iter() + .find(|index| matches!(index.ty, IndexType::Unique)) + .unwrap() + .clone(); + let (b_pos, b_column) = table + .columns() + .cloned() + .enumerate() + .find(|(_, column)| column.name() == "b") + .unwrap(); + let mut columns = BTreeMap::new(); + columns.insert(b_pos, b_column.clone()); + let covered_deserializers = vec![b_column.datatype().serializable()]; + + let target_pk = DataValue::Int32(3); + let covered_value = DataValue::Int32(4); + transaction.remove_tuple("t1", &target_pk)?; + + let mut iter = transaction.read_by_index( + kite_sql.state.table_cache(), + "t1".to_string().into(), + (Some(0), Some(1)), + columns, + unique_index, + vec![Range::Eq(covered_value.clone())], + false, + Some(covered_deserializers), + )?; + + let mut tuples = Vec::new(); + while let Some(tuple) = iter.next_tuple()? { + tuples.push(tuple); + } + + assert_eq!(tuples.len(), 1); + assert_eq!(tuples[0].pk, Some(target_pk)); + assert_eq!(tuples[0].values, vec![covered_value]); + + Ok(()) + } } diff --git a/src/storage/table_codec.rs b/src/storage/table_codec.rs index b46275ac..e7094dc6 100644 --- a/src/storage/table_codec.rs +++ b/src/storage/table_codec.rs @@ -1,9 +1,23 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::view::View; use crate::catalog::{ColumnRef, ColumnRelation, TableMeta}; use crate::errors::DatabaseError; use crate::serdes::{ReferenceSerialization, ReferenceTables}; -use crate::storage::{TableCache, Transaction}; -use crate::types::index::{Index, IndexId, IndexMeta, IndexType}; +use crate::storage::{PrimaryKeyRemap, TableCache, Transaction}; +use crate::types::index::{Index, IndexId, IndexMeta, IndexType, INDEX_ID_LEN}; use crate::types::serialize::TupleValueSerializableImpl; use crate::types::tuple::{Tuple, TupleId}; use crate::types::value::DataValue; @@ -16,6 +30,8 @@ use std::sync::LazyLock; pub(crate) const BOUND_MIN_TAG: u8 = u8::MIN; pub(crate) const BOUND_MAX_TAG: u8 = u8::MAX; +pub(crate) const NULL_TAG: u8 = 0u8; +pub(crate) const NOTNULL_TAG: u8 = 1u8; static ROOT_BYTES: LazyLock> = LazyLock::new(|| b"Root".to_vec()); static VIEW_BYTES: LazyLock> = LazyLock::new(|| b"View".to_vec()); @@ -285,7 +301,7 @@ impl TableCodec { #[inline] pub fn decode_tuple( deserializers: &[TupleValueSerializableImpl], - pk_indices: Option<&[usize]>, + pk_indices: &PrimaryKeyRemap, bytes: &[u8], values_len: usize, total_len: usize, @@ -383,6 +399,12 @@ impl TableCodec { Ok(key_prefix) } + pub fn decode_index_key(bytes: &[u8], ty: &LogicalType) -> Result { + // Hash + TypeTag + Bound Min + Index Id Len + Bound Min + let start = 8 + 1 + 1 + 1 + INDEX_ID_LEN; + DataValue::memcomparable_decode(&mut Cursor::new(&bytes[start..]), ty) + } + pub fn decode_index(bytes: &[u8]) -> Result { Ok(bincode::deserialize_from(&mut Cursor::new(bytes))?) } @@ -544,7 +566,7 @@ mod tests { use crate::serdes::ReferenceTables; use crate::storage::rocksdb::RocksTransaction; use crate::storage::table_codec::{BumpBytes, TableCodec}; - use crate::storage::Storage; + use crate::storage::{PrimaryKeyRemap, Storage}; use crate::types::index::{Index, IndexMeta, IndexType}; use crate::types::tuple::Tuple; use crate::types::value::DataValue; @@ -599,7 +621,13 @@ mod tests { tuple.pk = None; assert_eq!( - TableCodec::decode_tuple(&deserializers, None, &bytes, deserializers.len(), 2,)?, + TableCodec::decode_tuple( + &deserializers, + &PrimaryKeyRemap::None, + &bytes, + deserializers.len(), + 2, + )?, tuple ); diff --git a/src/types/evaluator/boolean.rs b/src/types/evaluator/boolean.rs index 95bde45a..8d6f99ec 100644 --- a/src/types/evaluator/boolean.rs +++ b/src/types/evaluator/boolean.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; diff --git a/src/types/evaluator/date.rs b/src/types/evaluator/date.rs index c31561e7..7289ab44 100644 --- a/src/types/evaluator/date.rs +++ b/src/types/evaluator/date.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/datetime.rs b/src/types/evaluator/datetime.rs index cd3e6634..708c005a 100644 --- a/src/types/evaluator/datetime.rs +++ b/src/types/evaluator/datetime.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/decimal.rs b/src/types/evaluator/decimal.rs index 077518f2..720aa65d 100644 --- a/src/types/evaluator/decimal.rs +++ b/src/types/evaluator/decimal.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/float32.rs b/src/types/evaluator/float32.rs index 1dfd6482..be278132 100644 --- a/src/types/evaluator/float32.rs +++ b/src/types/evaluator/float32.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; diff --git a/src/types/evaluator/float64.rs b/src/types/evaluator/float64.rs index 86e90e93..35a9e164 100644 --- a/src/types/evaluator/float64.rs +++ b/src/types/evaluator/float64.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; diff --git a/src/types/evaluator/int16.rs b/src/types/evaluator/int16.rs index ad5675a3..976c1502 100644 --- a/src/types/evaluator/int16.rs +++ b/src/types/evaluator/int16.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; use crate::types::DatabaseError; diff --git a/src/types/evaluator/int32.rs b/src/types/evaluator/int32.rs index 296dfe29..03ffddd4 100644 --- a/src/types/evaluator/int32.rs +++ b/src/types/evaluator/int32.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; use crate::types::DatabaseError; diff --git a/src/types/evaluator/int64.rs b/src/types/evaluator/int64.rs index 9f0be2ff..9a4727dd 100644 --- a/src/types/evaluator/int64.rs +++ b/src/types/evaluator/int64.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; use crate::types::DatabaseError; diff --git a/src/types/evaluator/int8.rs b/src/types/evaluator/int8.rs index ebda024e..fe5a7ccb 100644 --- a/src/types/evaluator/int8.rs +++ b/src/types/evaluator/int8.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::types::evaluator::DataValue; use crate::types::evaluator::{BinaryEvaluator, UnaryEvaluator}; use crate::types::DatabaseError; diff --git a/src/types/evaluator/mod.rs b/src/types/evaluator/mod.rs index b1201c2e..c66a60a7 100644 --- a/src/types/evaluator/mod.rs +++ b/src/types/evaluator/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod boolean; pub mod date; pub mod datetime; diff --git a/src/types/evaluator/null.rs b/src/types/evaluator/null.rs index f0995976..a9343055 100644 --- a/src/types/evaluator/null.rs +++ b/src/types/evaluator/null.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/time32.rs b/src/types/evaluator/time32.rs index 8b41acb0..b9be3128 100644 --- a/src/types/evaluator/time32.rs +++ b/src/types/evaluator/time32.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/time64.rs b/src/types/evaluator/time64.rs index b7cfc696..ee1dc763 100644 --- a/src/types/evaluator/time64.rs +++ b/src/types/evaluator/time64.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/tuple.rs b/src/types/evaluator/tuple.rs index 601568af..4561850f 100644 --- a/src/types/evaluator/tuple.rs +++ b/src/types/evaluator/tuple.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/uint16.rs b/src/types/evaluator/uint16.rs index fc23a0ae..70c1f13c 100644 --- a/src/types/evaluator/uint16.rs +++ b/src/types/evaluator/uint16.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/uint32.rs b/src/types/evaluator/uint32.rs index 2807517a..43409673 100644 --- a/src/types/evaluator/uint32.rs +++ b/src/types/evaluator/uint32.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/uint64.rs b/src/types/evaluator/uint64.rs index a5901954..723b272f 100644 --- a/src/types/evaluator/uint64.rs +++ b/src/types/evaluator/uint64.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/uint8.rs b/src/types/evaluator/uint8.rs index a652672f..6266bf71 100644 --- a/src/types/evaluator/uint8.rs +++ b/src/types/evaluator/uint8.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::numeric_binary_evaluator_definition; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/evaluator/utf8.rs b/src/types/evaluator/utf8.rs index c041fd0f..31af9db8 100644 --- a/src/types/evaluator/utf8.rs +++ b/src/types/evaluator/utf8.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::evaluator::BinaryEvaluator; use crate::types::evaluator::DataValue; diff --git a/src/types/index.rs b/src/types/index.rs index a1f8e2d8..570c49e1 100644 --- a/src/types/index.rs +++ b/src/types/index.rs @@ -1,7 +1,22 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::{TableCatalog, TableName}; use crate::errors::DatabaseError; use crate::expression::range_detacher::Range; use crate::expression::ScalarExpression; +use crate::types::serialize::TupleValueSerializableImpl; use crate::types::value::DataValue; use crate::types::{ColumnId, LogicalType}; use kite_sql_serde_macros::ReferenceSerialization; @@ -12,6 +27,8 @@ use std::sync::Arc; pub type IndexId = u32; pub type IndexMetaRef = Arc; +pub const INDEX_ID_LEN: usize = 4; + #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, ReferenceSerialization)] pub enum IndexType { PrimaryKey { is_multiple: bool }, @@ -24,6 +41,7 @@ pub enum IndexType { pub struct IndexInfo { pub(crate) meta: IndexMetaRef, pub(crate) range: Option, + pub(crate) covered_deserializers: Option>, } #[derive(Debug, Clone, Eq, PartialEq, Hash, ReferenceSerialization)] @@ -78,6 +96,9 @@ impl fmt::Display for IndexInfo { } else { write!(f, "EMPTY")?; } + if self.covered_deserializers.is_some() { + write!(f, " Covered")?; + } Ok(()) } diff --git a/src/types/mod.rs b/src/types/mod.rs index ca9376fb..6a17416f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub mod evaluator; pub mod index; pub mod serialize; diff --git a/src/types/serialize.rs b/src/types/serialize.rs index 39948d47..081a05dd 100644 --- a/src/types/serialize.rs +++ b/src/types/serialize.rs @@ -1,8 +1,23 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use crate::types::value::{DataValue, Utf8Type}; use crate::types::LogicalType; use bumpalo::collections::Vec; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use kite_sql_serde_macros::ReferenceSerialization; use ordered_float::OrderedFloat; use rust_decimal::Decimal; use sqlparser::ast::CharLengthUnits; @@ -41,7 +56,7 @@ pub trait TupleValueSerializable: Debug { } } -#[derive(Debug)] +#[derive(Debug, Clone, Eq, PartialEq, Hash, ReferenceSerialization)] pub enum TupleValueSerializableImpl { Boolean, Int8, diff --git a/src/types/tuple.rs b/src/types/tuple.rs index 54ed5f11..f53ce442 100644 --- a/src/types/tuple.rs +++ b/src/types/tuple.rs @@ -1,7 +1,22 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::ColumnRef; use crate::db::ResultIter; use crate::errors::DatabaseError; use crate::storage::table_codec::BumpBytes; +use crate::storage::PrimaryKeyRemap; use crate::types::serialize::{TupleValueSerializable, TupleValueSerializableImpl}; use crate::types::value::DataValue; use bumpalo::Bump; @@ -36,7 +51,7 @@ impl Tuple { #[inline] pub fn deserialize_from( deserializers: &[TupleValueSerializableImpl], - pk_indices: Option<&[usize]>, + pk_remap: &PrimaryKeyRemap, bytes: &[u8], values_len: usize, total_len: usize, @@ -57,11 +72,13 @@ impl Tuple { } deserializer.filling_value(&mut cursor, &mut values)?; } + let pk = if let PrimaryKeyRemap::Indices(indices) = pk_remap { + Some(Tuple::primary_projection(indices, &values)) + } else { + None + }; - Ok(Tuple { - pk: pk_indices.map(|pk_indices| Tuple::primary_projection(pk_indices, &values)), - values, - }) + Ok(Tuple { pk, values }) } /// e.g.: bits(u8)..|data_0(len for utf8_1)|utf8_0|data_1| @@ -137,6 +154,7 @@ pub fn create_table(iter: I) -> Result { #[cfg(all(test, not(target_arch = "wasm32")))] mod tests { use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRef}; + use crate::storage::PrimaryKeyRemap; use crate::types::tuple::Tuple; use crate::types::value::{DataValue, Utf8Type}; use crate::types::LogicalType; @@ -325,7 +343,7 @@ mod tests { { let tuple_0 = Tuple::deserialize_from( &serializers, - Some(vec![0]).as_deref(), + &PrimaryKeyRemap::Indices(vec![0]), &tuples[0].serialize_to(&serializers, &arena).unwrap(), serializers.len(), columns.len(), @@ -337,7 +355,7 @@ mod tests { { let tuple_1 = Tuple::deserialize_from( &serializers, - Some(vec![0]).as_deref(), + &PrimaryKeyRemap::Indices(vec![0]), &tuples[1].serialize_to(&serializers, &arena).unwrap(), serializers.len(), columns.len(), @@ -356,7 +374,7 @@ mod tests { ]; let tuple_2 = Tuple::deserialize_from( &projection_serializers, - Some(vec![0]).as_deref(), + &PrimaryKeyRemap::Indices(vec![0]), &tuples[0].serialize_to(&serializers, &arena).unwrap(), 2, columns.len(), @@ -381,7 +399,7 @@ mod tests { let tuple_3 = Tuple::deserialize_from( &multiple_pk_serializers, - Some(vec![4, 2]).as_deref(), + &PrimaryKeyRemap::Indices(vec![4, 2]), &tuples[0].serialize_to(&serializers, &arena).unwrap(), serializers.len(), columns.len(), diff --git a/src/types/tuple_builder.rs b/src/types/tuple_builder.rs index 0b196c25..eac2d32a 100644 --- a/src/types/tuple_builder.rs +++ b/src/types/tuple_builder.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::catalog::PrimaryKeyIndices; use crate::errors::DatabaseError; use crate::types::tuple::{Schema, Tuple}; diff --git a/src/types/value.rs b/src/types/value.rs index 9a024b78..3a9bf22d 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -1,6 +1,21 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use super::LogicalType; use crate::errors::DatabaseError; -use crate::storage::table_codec::{BumpBytes, BOUND_MAX_TAG, BOUND_MIN_TAG}; +use crate::storage::table_codec::{BumpBytes, BOUND_MAX_TAG, NOTNULL_TAG, NULL_TAG}; +use byteorder::ReadBytesExt; use chrono::format::{DelayedFormat, StrftimeItems}; use chrono::{DateTime, Datelike, NaiveDate, NaiveDateTime, NaiveTime, Timelike, Utc}; use itertools::Itertools; @@ -11,7 +26,7 @@ use sqlparser::ast::CharLengthUnits; use std::cmp::Ordering; use std::fmt::Formatter; use std::hash::Hash; -use std::io::Write; +use std::io::{Read, Write}; use std::str::FromStr; use std::sync::LazyLock; use std::{cmp, fmt, mem}; @@ -206,6 +221,14 @@ macro_rules! encode_u { }; } +macro_rules! decode_u { + ($reader:ident, $ty:ty) => {{ + let mut buf = [0u8; std::mem::size_of::<$ty>()]; + $reader.read_exact(&mut buf)?; + <$ty>::from_be_bytes(buf) + }}; +} + impl Eq for DataValue {} impl Hash for DataValue { @@ -576,43 +599,97 @@ impl DataValue { // // Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format #[inline] - fn encode_bytes(b: &mut BumpBytes, data: &[u8]) { + // FIXME + fn encode_string(b: &mut BumpBytes, data: &[u8]) { let d_len = data.len(); - let realloc_size = (d_len / ENCODE_GROUP_SIZE + 1) * (ENCODE_GROUP_SIZE + 1); - Self::realloc_bytes(b, realloc_size); + let needed_groups = d_len / ENCODE_GROUP_SIZE + 1; + Self::realloc_bytes(b, needed_groups * (ENCODE_GROUP_SIZE + 1)); let mut idx = 0; - while idx <= d_len { - let remain = d_len - idx; - let pad_count: usize; + + loop { + let remain = d_len.saturating_sub(idx); if remain >= ENCODE_GROUP_SIZE { b.extend_from_slice(&data[idx..idx + ENCODE_GROUP_SIZE]); - pad_count = 0; - } else { - pad_count = ENCODE_GROUP_SIZE - remain; + b.push(ENCODE_MARKER); + idx += ENCODE_GROUP_SIZE; + continue; + } + + let pad_count = ENCODE_GROUP_SIZE - remain; + + if remain > 0 { b.extend_from_slice(&data[idx..]); - b.extend_from_slice(&vec![0; pad_count]); + } + + for _ in 0..pad_count { + b.push(0); } b.push(ENCODE_MARKER - pad_count as u8); - idx += ENCODE_GROUP_SIZE; + break; } } #[inline] - fn realloc_bytes(b: &mut BumpBytes, size: usize) { - let len = b.len(); + fn decode_string(reader: &mut R) -> std::io::Result> { + let mut result = Vec::new(); + + loop { + let mut group = [0u8; ENCODE_GROUP_SIZE]; + reader.read_exact(&mut group)?; + + let mut marker = [0u8; 1]; + reader.read_exact(&mut marker)?; + let marker = marker[0]; + + let pad_count = (ENCODE_MARKER - marker) as usize; - if size > len { - b.reserve(size - len); - b.resize(size, 0); + if pad_count > ENCODE_GROUP_SIZE { + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + "memcomparable string marker out of range", + )); + } + + let data_len = ENCODE_GROUP_SIZE - pad_count; + result.extend_from_slice(&group[..data_len]); + + if pad_count != 0 { + break; + } } + + Ok(result) } #[inline] - pub fn memcomparable_encode(&self, b: &mut BumpBytes) -> Result<(), DatabaseError> { + fn realloc_bytes(b: &mut BumpBytes, size: usize) { + if size > 0 { + b.reserve(size); + } + } + + #[inline(always)] + pub fn memcomparable_encode_with_null_order( + &self, + b: &mut BumpBytes, + nulls_first: bool, + ) -> Result<(), DatabaseError> { + let (null_tag, not_null_tag) = if nulls_first { + (NULL_TAG, NOTNULL_TAG) + } else { + (NOTNULL_TAG, NULL_TAG) + }; + if let DataValue::Null = self { + b.push(null_tag); + return Ok(()); + } + b.push(not_null_tag); + match self { + DataValue::Null => (), DataValue::Int8(v) => encode_u!(b, *v as u8 ^ 0x80_u8), DataValue::Int16(v) => encode_u!(b, *v as u16 ^ 0x8000_u16), DataValue::Int32(v) | DataValue::Date32(v) => { @@ -625,7 +702,7 @@ impl DataValue { DataValue::UInt16(v) => encode_u!(b, v), DataValue::UInt32(v) | DataValue::Time32(v, ..) => encode_u!(b, v), DataValue::UInt64(v) => encode_u!(b, v), - DataValue::Utf8 { value: v, .. } => Self::encode_bytes(b, v.as_bytes()), + DataValue::Utf8 { value: v, .. } => Self::encode_string(b, v.as_bytes()), DataValue::Boolean(v) => b.push(if *v { b'1' } else { b'0' }), DataValue::Float32(f) => { let mut u = f.to_bits(); @@ -649,17 +726,14 @@ impl DataValue { encode_u!(b, u); } - DataValue::Null => (), DataValue::Decimal(v) => Self::serialize_decimal(*v, b)?, DataValue::Tuple(values, is_upper) => { let last = values.len() - 1; for (i, v) in values.iter().enumerate() { v.memcomparable_encode(b)?; - if (v.is_null() || i == last) && *is_upper { + if i == last && *is_upper { b.push(BOUND_MAX_TAG); - } else { - b.push(BOUND_MIN_TAG); } } } @@ -668,6 +742,90 @@ impl DataValue { Ok(()) } + #[inline] + pub fn memcomparable_encode(&self, b: &mut BumpBytes) -> Result<(), DatabaseError> { + self.memcomparable_encode_with_null_order(b, true) + } + + pub fn memcomparable_decode( + reader: &mut R, + ty: &LogicalType, + ) -> Result { + if reader.read_u8()? == 0u8 { + return Ok(DataValue::Null); + } + match ty { + LogicalType::SqlNull => Ok(DataValue::Null), + LogicalType::Tinyint => { + let u = decode_u!(reader, u8); + Ok(DataValue::Int8((u ^ 0x80) as i8)) + } + LogicalType::Smallint => { + let u = decode_u!(reader, u16); + Ok(DataValue::Int16((u ^ 0x8000) as i16)) + } + LogicalType::Integer | LogicalType::Date | LogicalType::Time(_) => { + let u = decode_u!(reader, u32); + Ok(DataValue::Int32((u ^ 0x8000_0000) as i32)) + } + LogicalType::Bigint | LogicalType::DateTime | LogicalType::TimeStamp(..) => { + let u = decode_u!(reader, u64); + Ok(DataValue::Int64((u ^ 0x8000_0000_0000_0000) as i64)) + } + LogicalType::UTinyint => Ok(DataValue::UInt8(decode_u!(reader, u8))), + LogicalType::USmallint => Ok(DataValue::UInt16(decode_u!(reader, u16))), + LogicalType::UInteger => Ok(DataValue::UInt32(decode_u!(reader, u32))), + LogicalType::UBigint => Ok(DataValue::UInt64(decode_u!(reader, u64))), + LogicalType::Float => { + let mut u = decode_u!(reader, u32); + + // 反向还原 + if (u & 0x8000_0000) != 0 { + u &= !0x8000_0000; + } else { + u = !u; + } + + Ok(DataValue::Float32(f32::from_bits(u).into())) + } + LogicalType::Double => { + let mut u = decode_u!(reader, u64); + + if (u & 0x8000_0000_0000_0000) != 0 { + u &= !0x8000_0000_0000_0000; + } else { + u = !u; + } + + Ok(DataValue::Float64(f64::from_bits(u).into())) + } + LogicalType::Boolean => { + let mut b = [0u8; 1]; + reader.read_exact(&mut b)?; + Ok(DataValue::Boolean(b[0] == b'1')) + } + LogicalType::Varchar(len, unit) => Ok(DataValue::Utf8 { + value: String::from_utf8(Self::decode_string(reader)?)?, + ty: Utf8Type::Variable(*len), + unit: *unit, + }), + LogicalType::Char(len, unit) => Ok(DataValue::Utf8 { + value: String::from_utf8(Self::decode_string(reader)?)?, + ty: Utf8Type::Fixed(*len), + unit: *unit, + }), + LogicalType::Decimal(..) => Ok(DataValue::Decimal(Self::deserialize_decimal(reader)?)), + LogicalType::Tuple(tys) => { + let mut values = Vec::with_capacity(tys.len()); + + for ty in tys { + values.push(Self::memcomparable_decode(reader, ty)?); + } + Ok(DataValue::Tuple(values, false)) + } + } + } + // https://github.com/risingwavelabs/memcomparable/blob/main/src/ser.rs#L468 pub fn serialize_decimal(decimal: Decimal, bytes: &mut BumpBytes) -> Result<(), DatabaseError> { if decimal.is_zero() { @@ -787,6 +945,64 @@ impl DataValue { (e100 as i8, byte_array) } + pub fn deserialize_decimal(mut reader: R) -> Result { + // decode exponent + let flag = reader.read_u8()?; + let exponent = match flag { + 0x08 => !reader.read_u8()? as i8, + 0x09..=0x13 => (0x13 - flag) as i8, + 0x14 => -(reader.read_u8()? as i8), + 0x15 => return Ok(Decimal::ZERO), + 0x16 => -!(reader.read_u8()? as i8), + 0x17..=0x21 => (flag - 0x17) as i8, + 0x22 => reader.read_u8()? as i8, + b => { + return Err(DatabaseError::InvalidValue(format!( + "invalid decimal exponent: {b}" + ))) + } + }; + // decode mantissa + let neg = (0x07..0x15).contains(&flag); + let mut mantissa: i128 = 0; + let mut mlen = 0i8; + loop { + let mut b = reader.read_u8()?; + if neg { + b = !b; + } + let x = b / 2; + mantissa = mantissa * 100 + x as i128; + mlen += 1; + if b & 1 == 0 { + break; + } + } + + // get scale + let mut scale = (mlen - exponent) * 2; + if scale <= 0 { + // e.g. 1(mantissa) + 2(exponent) (which is 100). + for _i in 0..-scale { + mantissa *= 10; + } + scale = 0; + } else if mantissa % 10 == 0 { + // Remove unnecessary zeros. + // e.g. 0.01_11_10 should be 0.01_11_1 + mantissa /= 10; + scale -= 1; + } + + if neg { + mantissa = -mantissa; + } + Ok(rust_decimal::Decimal::from_i128_with_scale( + mantissa, + scale as u32, + )) + } + #[inline] pub fn is_true(&self) -> Result { if self.is_null() { @@ -1939,10 +2155,13 @@ impl fmt::Debug for DataValue { mod test { use crate::errors::DatabaseError; use crate::storage::table_codec::BumpBytes; - use crate::types::value::DataValue; + use crate::types::value::{DataValue, Utf8Type}; + use crate::types::LogicalType; use bumpalo::Bump; use ordered_float::OrderedFloat; use rust_decimal::Decimal; + use sqlparser::ast::CharLengthUnits; + use std::io::Cursor; #[test] fn test_mem_comparable_null() -> Result<(), DatabaseError> { @@ -1952,10 +2171,15 @@ mod test { let mut key_i8_2 = BumpBytes::new_in(&arena); let mut key_i8_3 = BumpBytes::new_in(&arena); - DataValue::Null.memcomparable_encode(&mut key_i8_0)?; - DataValue::Int8(i8::MIN).memcomparable_encode(&mut key_i8_1)?; - DataValue::Int8(-1_i8).memcomparable_encode(&mut key_i8_2)?; - DataValue::Int8(i8::MAX).memcomparable_encode(&mut key_i8_3)?; + let value_0 = DataValue::Null; + let value_1 = DataValue::Int8(i8::MIN); + let value_2 = DataValue::Int8(-1_i8); + let value_3 = DataValue::Int8(i8::MAX); + + value_0.memcomparable_encode(&mut key_i8_0)?; + value_1.memcomparable_encode(&mut key_i8_1)?; + value_2.memcomparable_encode(&mut key_i8_2)?; + value_3.memcomparable_encode(&mut key_i8_3)?; println!("{:?} < {:?}", key_i8_0, key_i8_1); println!("{:?} < {:?}", key_i8_1, key_i8_2); @@ -1964,114 +2188,389 @@ mod test { assert!(key_i8_1 < key_i8_2); assert!(key_i8_2 < key_i8_3); + assert_eq!( + value_0, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_0.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + value_1, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_1.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + value_2, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_2.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + value_3, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_3.as_slice()), + &LogicalType::Tinyint + )? + ); + Ok(()) } #[test] fn test_mem_comparable_int() -> Result<(), DatabaseError> { let arena = Bump::new(); + + // ---------- Int8 ---------- + let mut key_i8_0 = BumpBytes::new_in(&arena); let mut key_i8_1 = BumpBytes::new_in(&arena); let mut key_i8_2 = BumpBytes::new_in(&arena); let mut key_i8_3 = BumpBytes::new_in(&arena); - DataValue::Int8(i8::MIN).memcomparable_encode(&mut key_i8_1)?; - DataValue::Int8(-1_i8).memcomparable_encode(&mut key_i8_2)?; - DataValue::Int8(i8::MAX).memcomparable_encode(&mut key_i8_3)?; + let v_i8_0 = DataValue::Null; + let v_i8_1 = DataValue::Int8(i8::MIN); + let v_i8_2 = DataValue::Int8(-1); + let v_i8_3 = DataValue::Int8(i8::MAX); - println!("{:?} < {:?}", key_i8_1, key_i8_2); - println!("{:?} < {:?}", key_i8_2, key_i8_3); + v_i8_0.memcomparable_encode(&mut key_i8_0)?; + v_i8_1.memcomparable_encode(&mut key_i8_1)?; + v_i8_2.memcomparable_encode(&mut key_i8_2)?; + v_i8_3.memcomparable_encode(&mut key_i8_3)?; + + assert!(key_i8_0 < key_i8_1); assert!(key_i8_1 < key_i8_2); assert!(key_i8_2 < key_i8_3); + assert_eq!( + v_i8_0, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_0.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + v_i8_1, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_1.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + v_i8_2, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_2.as_slice()), + &LogicalType::Tinyint + )? + ); + assert_eq!( + v_i8_3, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i8_3.as_slice()), + &LogicalType::Tinyint + )? + ); + + // ---------- Int16 ---------- + let mut key_i16_0 = BumpBytes::new_in(&arena); let mut key_i16_1 = BumpBytes::new_in(&arena); let mut key_i16_2 = BumpBytes::new_in(&arena); let mut key_i16_3 = BumpBytes::new_in(&arena); - DataValue::Int16(i16::MIN).memcomparable_encode(&mut key_i16_1)?; - DataValue::Int16(-1_i16).memcomparable_encode(&mut key_i16_2)?; - DataValue::Int16(i16::MAX).memcomparable_encode(&mut key_i16_3)?; + let v_i16_0 = DataValue::Null; + let v_i16_1 = DataValue::Int16(i16::MIN); + let v_i16_2 = DataValue::Int16(-1); + let v_i16_3 = DataValue::Int16(i16::MAX); + + v_i16_0.memcomparable_encode(&mut key_i16_0)?; + v_i16_1.memcomparable_encode(&mut key_i16_1)?; + v_i16_2.memcomparable_encode(&mut key_i16_2)?; + v_i16_3.memcomparable_encode(&mut key_i16_3)?; - println!("{:?} < {:?}", key_i16_1, key_i16_2); - println!("{:?} < {:?}", key_i16_2, key_i16_3); + assert!(key_i16_0 < key_i16_1); assert!(key_i16_1 < key_i16_2); assert!(key_i16_2 < key_i16_3); + assert_eq!( + v_i16_0, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i16_0.as_slice()), + &LogicalType::Smallint + )? + ); + assert_eq!( + v_i16_1, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i16_1.as_slice()), + &LogicalType::Smallint + )? + ); + assert_eq!( + v_i16_2, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i16_2.as_slice()), + &LogicalType::Smallint + )? + ); + assert_eq!( + v_i16_3, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i16_3.as_slice()), + &LogicalType::Smallint + )? + ); + + // ---------- Int32 ---------- + let mut key_i32_0 = BumpBytes::new_in(&arena); let mut key_i32_1 = BumpBytes::new_in(&arena); let mut key_i32_2 = BumpBytes::new_in(&arena); let mut key_i32_3 = BumpBytes::new_in(&arena); - DataValue::Int32(i32::MIN).memcomparable_encode(&mut key_i32_1)?; - DataValue::Int32(-1_i32).memcomparable_encode(&mut key_i32_2)?; - DataValue::Int32(i32::MAX).memcomparable_encode(&mut key_i32_3)?; + let v_i32_0 = DataValue::Null; + let v_i32_1 = DataValue::Int32(i32::MIN); + let v_i32_2 = DataValue::Int32(-1); + let v_i32_3 = DataValue::Int32(i32::MAX); + + v_i32_0.memcomparable_encode(&mut key_i32_0)?; + v_i32_1.memcomparable_encode(&mut key_i32_1)?; + v_i32_2.memcomparable_encode(&mut key_i32_2)?; + v_i32_3.memcomparable_encode(&mut key_i32_3)?; - println!("{:?} < {:?}", key_i32_1, key_i32_2); - println!("{:?} < {:?}", key_i32_2, key_i32_3); + assert!(key_i32_0 < key_i32_1); assert!(key_i32_1 < key_i32_2); assert!(key_i32_2 < key_i32_3); + assert_eq!( + v_i32_0, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i32_0.as_slice()), + &LogicalType::Integer + )? + ); + assert_eq!( + v_i32_1, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i32_1.as_slice()), + &LogicalType::Integer + )? + ); + assert_eq!( + v_i32_2, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i32_2.as_slice()), + &LogicalType::Integer + )? + ); + assert_eq!( + v_i32_3, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i32_3.as_slice()), + &LogicalType::Integer + )? + ); + + // ---------- Int64 ---------- + let mut key_i64_0 = BumpBytes::new_in(&arena); let mut key_i64_1 = BumpBytes::new_in(&arena); let mut key_i64_2 = BumpBytes::new_in(&arena); let mut key_i64_3 = BumpBytes::new_in(&arena); - DataValue::Int64(i64::MIN).memcomparable_encode(&mut key_i64_1)?; - DataValue::Int64(-1_i64).memcomparable_encode(&mut key_i64_2)?; - DataValue::Int64(i64::MAX).memcomparable_encode(&mut key_i64_3)?; + let v_i64_0 = DataValue::Null; + let v_i64_1 = DataValue::Int64(i64::MIN); + let v_i64_2 = DataValue::Int64(-1); + let v_i64_3 = DataValue::Int64(i64::MAX); - println!("{:?} < {:?}", key_i64_1, key_i64_2); - println!("{:?} < {:?}", key_i64_2, key_i64_3); + v_i64_0.memcomparable_encode(&mut key_i64_0)?; + v_i64_1.memcomparable_encode(&mut key_i64_1)?; + v_i64_2.memcomparable_encode(&mut key_i64_2)?; + v_i64_3.memcomparable_encode(&mut key_i64_3)?; + + assert!(key_i64_0 < key_i64_1); assert!(key_i64_1 < key_i64_2); assert!(key_i64_2 < key_i64_3); + assert_eq!( + v_i64_0, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i64_0.as_slice()), + &LogicalType::Bigint + )? + ); + assert_eq!( + v_i64_1, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i64_1.as_slice()), + &LogicalType::Bigint + )? + ); + assert_eq!( + v_i64_2, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i64_2.as_slice()), + &LogicalType::Bigint + )? + ); + assert_eq!( + v_i64_3, + DataValue::memcomparable_decode( + &mut Cursor::new(key_i64_3.as_slice()), + &LogicalType::Bigint + )? + ); + Ok(()) } #[test] fn test_mem_comparable_float() -> Result<(), DatabaseError> { let arena = Bump::new(); + + // ---------- Float32 ---------- + let mut key_f32_0 = BumpBytes::new_in(&arena); let mut key_f32_1 = BumpBytes::new_in(&arena); let mut key_f32_2 = BumpBytes::new_in(&arena); let mut key_f32_3 = BumpBytes::new_in(&arena); - DataValue::Float32(OrderedFloat(f32::MIN)).memcomparable_encode(&mut key_f32_1)?; - DataValue::Float32(OrderedFloat(-1_f32)).memcomparable_encode(&mut key_f32_2)?; - DataValue::Float32(OrderedFloat(f32::MAX)).memcomparable_encode(&mut key_f32_3)?; + let v_f32_0 = DataValue::Null; + let v_f32_1 = DataValue::Float32(OrderedFloat(f32::MIN)); + let v_f32_2 = DataValue::Float32(OrderedFloat(-1.0)); + let v_f32_3 = DataValue::Float32(OrderedFloat(f32::MAX)); + + v_f32_0.memcomparable_encode(&mut key_f32_0)?; + v_f32_1.memcomparable_encode(&mut key_f32_1)?; + v_f32_2.memcomparable_encode(&mut key_f32_2)?; + v_f32_3.memcomparable_encode(&mut key_f32_3)?; - println!("{:?} < {:?}", key_f32_1, key_f32_2); - println!("{:?} < {:?}", key_f32_2, key_f32_3); + assert!(key_f32_0 < key_f32_1); assert!(key_f32_1 < key_f32_2); assert!(key_f32_2 < key_f32_3); + assert_eq!( + v_f32_0, + DataValue::memcomparable_decode(&mut Cursor::new(&key_f32_0[..]), &LogicalType::Float)? + ); + assert_eq!( + v_f32_1, + DataValue::memcomparable_decode(&mut Cursor::new(&key_f32_1[..]), &LogicalType::Float)? + ); + assert_eq!( + v_f32_2, + DataValue::memcomparable_decode(&mut Cursor::new(&key_f32_2[..]), &LogicalType::Float)? + ); + assert_eq!( + v_f32_3, + DataValue::memcomparable_decode(&mut Cursor::new(&key_f32_3[..]), &LogicalType::Float)? + ); + + // ---------- Float64 ---------- + let mut key_f64_0 = BumpBytes::new_in(&arena); let mut key_f64_1 = BumpBytes::new_in(&arena); let mut key_f64_2 = BumpBytes::new_in(&arena); let mut key_f64_3 = BumpBytes::new_in(&arena); - DataValue::Float64(OrderedFloat(f64::MIN)).memcomparable_encode(&mut key_f64_1)?; - DataValue::Float64(OrderedFloat(-1_f64)).memcomparable_encode(&mut key_f64_2)?; - DataValue::Float64(OrderedFloat(f64::MAX)).memcomparable_encode(&mut key_f64_3)?; + let v_f64_0 = DataValue::Null; + let v_f64_1 = DataValue::Float64(OrderedFloat(f64::MIN)); + let v_f64_2 = DataValue::Float64(OrderedFloat(-1.0)); + let v_f64_3 = DataValue::Float64(OrderedFloat(f64::MAX)); - println!("{:?} < {:?}", key_f64_1, key_f64_2); - println!("{:?} < {:?}", key_f64_2, key_f64_3); + v_f64_0.memcomparable_encode(&mut key_f64_0)?; + v_f64_1.memcomparable_encode(&mut key_f64_1)?; + v_f64_2.memcomparable_encode(&mut key_f64_2)?; + v_f64_3.memcomparable_encode(&mut key_f64_3)?; + + assert!(key_f64_0 < key_f64_1); assert!(key_f64_1 < key_f64_2); assert!(key_f64_2 < key_f64_3); + assert_eq!( + v_f64_0, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_f64_0[..]), + &LogicalType::Double + )? + ); + assert_eq!( + v_f64_1, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_f64_1[..]), + &LogicalType::Double + )? + ); + assert_eq!( + v_f64_2, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_f64_2[..]), + &LogicalType::Double + )? + ); + assert_eq!( + v_f64_3, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_f64_3[..]), + &LogicalType::Double + )? + ); + Ok(()) } #[test] fn test_mem_comparable_decimal() -> Result<(), DatabaseError> { let arena = Bump::new(); - let mut key_deciaml_1 = BumpBytes::new_in(&arena); - let mut key_deciaml_2 = BumpBytes::new_in(&arena); - let mut key_deciaml_3 = BumpBytes::new_in(&arena); - DataValue::Decimal(Decimal::MIN).memcomparable_encode(&mut key_deciaml_1)?; - DataValue::Decimal(Decimal::new(-1, 0)).memcomparable_encode(&mut key_deciaml_2)?; - DataValue::Decimal(Decimal::MAX).memcomparable_encode(&mut key_deciaml_3)?; - - println!("{:?} < {:?}", key_deciaml_1, key_deciaml_2); - println!("{:?} < {:?}", key_deciaml_2, key_deciaml_3); - assert!(key_deciaml_1 < key_deciaml_2); - assert!(key_deciaml_2 < key_deciaml_3); + let mut key_decimal_0 = BumpBytes::new_in(&arena); + let mut key_decimal_1 = BumpBytes::new_in(&arena); + let mut key_decimal_2 = BumpBytes::new_in(&arena); + let mut key_decimal_3 = BumpBytes::new_in(&arena); + + let v_decimal_0 = DataValue::Null; + let v_decimal_1 = DataValue::Decimal(Decimal::MIN); + let v_decimal_2 = DataValue::Decimal(Decimal::new(-1, 0)); + let v_decimal_3 = DataValue::Decimal(Decimal::MAX); + + v_decimal_0.memcomparable_encode(&mut key_decimal_0)?; + v_decimal_1.memcomparable_encode(&mut key_decimal_1)?; + v_decimal_2.memcomparable_encode(&mut key_decimal_2)?; + v_decimal_3.memcomparable_encode(&mut key_decimal_3)?; + + println!("{:?} < {:?}", key_decimal_0, key_decimal_1); + println!("{:?} < {:?}", key_decimal_1, key_decimal_2); + println!("{:?} < {:?}", key_decimal_2, key_decimal_3); + + assert!(key_decimal_0 < key_decimal_1); + assert!(key_decimal_1 < key_decimal_2); + assert!(key_decimal_2 < key_decimal_3); + + assert_eq!( + v_decimal_0, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_decimal_0[..]), + &LogicalType::Decimal(None, None) + )? + ); + assert_eq!( + v_decimal_1, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_decimal_1[..]), + &LogicalType::Decimal(None, None) + )? + ); + assert_eq!( + v_decimal_2, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_decimal_2[..]), + &LogicalType::Decimal(None, None) + )? + ); + assert_eq!( + v_decimal_3, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_decimal_3[..]), + &LogicalType::Decimal(None, None) + )? + ); Ok(()) } @@ -2079,61 +2578,205 @@ mod test { #[test] fn test_mem_comparable_tuple_lower() -> Result<(), DatabaseError> { let arena = Bump::new(); + let mut key_tuple_1 = BumpBytes::new_in(&arena); let mut key_tuple_2 = BumpBytes::new_in(&arena); let mut key_tuple_3 = BumpBytes::new_in(&arena); - DataValue::Tuple( + let v_tuple_1 = DataValue::Tuple( vec![DataValue::Null, DataValue::Int8(0), DataValue::Int8(1)], false, - ) - .memcomparable_encode(&mut key_tuple_1)?; - DataValue::Tuple( + ); + + let v_tuple_2 = DataValue::Tuple( vec![DataValue::Int8(0), DataValue::Int8(0), DataValue::Int8(1)], false, - ) - .memcomparable_encode(&mut key_tuple_2)?; - DataValue::Tuple( + ); + + let v_tuple_3 = DataValue::Tuple( vec![DataValue::Int8(0), DataValue::Int8(0), DataValue::Int8(2)], false, - ) - .memcomparable_encode(&mut key_tuple_3)?; + ); + + v_tuple_1.memcomparable_encode(&mut key_tuple_1)?; + v_tuple_2.memcomparable_encode(&mut key_tuple_2)?; + v_tuple_3.memcomparable_encode(&mut key_tuple_3)?; println!("{:?} < {:?}", key_tuple_1, key_tuple_2); println!("{:?} < {:?}", key_tuple_2, key_tuple_3); + assert!(key_tuple_1 < key_tuple_2); assert!(key_tuple_2 < key_tuple_3); + assert_eq!( + v_tuple_1, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_tuple_1[..]), + &LogicalType::Tuple(vec![ + LogicalType::Tinyint, + LogicalType::Tinyint, + LogicalType::Tinyint, + ]) + )? + ); + assert_eq!( + v_tuple_2, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_tuple_2[..]), + &LogicalType::Tuple(vec![ + LogicalType::Tinyint, + LogicalType::Tinyint, + LogicalType::Tinyint, + ]) + )? + ); + assert_eq!( + v_tuple_3, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_tuple_3[..]), + &LogicalType::Tuple(vec![ + LogicalType::Tinyint, + LogicalType::Tinyint, + LogicalType::Tinyint, + ]) + )? + ); + Ok(()) } #[test] fn test_mem_comparable_tuple_upper() -> Result<(), DatabaseError> { + use DataValue::*; + + fn logical_eq(lhs: &DataValue, rhs: &DataValue) -> bool { + match (lhs, rhs) { + (Tuple(lv, _), Tuple(rv, _)) => { + lv.len() == rv.len() && lv.iter().zip(rv.iter()).all(|(l, r)| logical_eq(l, r)) + } + _ => lhs == rhs, + } + } + let arena = Bump::new(); + let mut key_tuple_1 = BumpBytes::new_in(&arena); let mut key_tuple_2 = BumpBytes::new_in(&arena); let mut key_tuple_3 = BumpBytes::new_in(&arena); - DataValue::Tuple( - vec![DataValue::Null, DataValue::Int8(0), DataValue::Int8(1)], - true, - ) - .memcomparable_encode(&mut key_tuple_1)?; - DataValue::Tuple( - vec![DataValue::Int8(0), DataValue::Int8(0), DataValue::Int8(1)], - true, - ) - .memcomparable_encode(&mut key_tuple_2)?; - DataValue::Tuple( - vec![DataValue::Int8(0), DataValue::Int8(0), DataValue::Int8(2)], - true, - ) - .memcomparable_encode(&mut key_tuple_3)?; + let v_tuple_1 = Tuple( + vec![Null, Int8(0), Int8(1)], + true, // upper bound + ); - println!("{:?} < {:?}", key_tuple_2, key_tuple_3); - println!("{:?} < {:?}", key_tuple_3, key_tuple_1); + let v_tuple_2 = Tuple(vec![Int8(0), Int8(0), Int8(1)], true); + + let v_tuple_3 = Tuple(vec![Int8(0), Int8(0), Int8(2)], true); + + v_tuple_1.memcomparable_encode(&mut key_tuple_1)?; + v_tuple_2.memcomparable_encode(&mut key_tuple_2)?; + v_tuple_3.memcomparable_encode(&mut key_tuple_3)?; + + assert!(key_tuple_1 < key_tuple_2); assert!(key_tuple_2 < key_tuple_3); - assert!(key_tuple_3 < key_tuple_1); + + let ty = LogicalType::Tuple(vec![ + LogicalType::Tinyint, + LogicalType::Tinyint, + LogicalType::Tinyint, + ]); + + let d1 = DataValue::memcomparable_decode(&mut Cursor::new(&key_tuple_1[..]), &ty)?; + let d2 = DataValue::memcomparable_decode(&mut Cursor::new(&key_tuple_2[..]), &ty)?; + let d3 = DataValue::memcomparable_decode(&mut Cursor::new(&key_tuple_3[..]), &ty)?; + + assert!(logical_eq(&v_tuple_1, &d1)); + assert!(logical_eq(&v_tuple_2, &d2)); + assert!(logical_eq(&v_tuple_3, &d3)); + + Ok(()) + } + + #[test] + fn test_mem_comparable_utf8() -> Result<(), DatabaseError> { + let arena = Bump::new(); + + let mut key_null = BumpBytes::new_in(&arena); + let mut key_a = BumpBytes::new_in(&arena); + let mut key_ab = BumpBytes::new_in(&arena); + let mut key_b = BumpBytes::new_in(&arena); + let mut key_zh = BumpBytes::new_in(&arena); + + let v_null = DataValue::Null; + + let v_a = DataValue::Utf8 { + value: "a".to_string(), + ty: Utf8Type::Variable(None), + unit: CharLengthUnits::Characters, + }; + + let v_ab = DataValue::Utf8 { + value: "ab".to_string(), + ty: Utf8Type::Variable(None), + unit: CharLengthUnits::Characters, + }; + + let v_b = DataValue::Utf8 { + value: "b".to_string(), + ty: Utf8Type::Variable(None), + unit: CharLengthUnits::Characters, + }; + + let v_zh = DataValue::Utf8 { + value: "中".to_string(), + ty: Utf8Type::Variable(None), + unit: CharLengthUnits::Characters, + }; + + v_null.memcomparable_encode(&mut key_null)?; + v_a.memcomparable_encode(&mut key_a)?; + v_ab.memcomparable_encode(&mut key_ab)?; + v_b.memcomparable_encode(&mut key_b)?; + v_zh.memcomparable_encode(&mut key_zh)?; + + // ordering + assert!(key_null < key_a); + assert!(key_a < key_ab); + assert!(key_ab < key_b); + assert!(key_b < key_zh); + + // decode check + assert_eq!( + v_a, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_a[..]), + &LogicalType::Varchar(None, CharLengthUnits::Characters) + )? + ); + + assert_eq!( + v_ab, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_ab[..]), + &LogicalType::Varchar(None, CharLengthUnits::Characters) + )? + ); + + assert_eq!( + v_b, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_b[..]), + &LogicalType::Varchar(None, CharLengthUnits::Characters) + )? + ); + + assert_eq!( + v_zh, + DataValue::memcomparable_decode( + &mut Cursor::new(&key_zh[..]), + &LogicalType::Varchar(None, CharLengthUnits::Characters) + )? + ); Ok(()) } diff --git a/src/utils/lru.rs b/src/utils/lru.rs index 87bbf1a3..bc8417dd 100644 --- a/src/utils/lru.rs +++ b/src/utils/lru.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::errors::DatabaseError; use parking_lot::Mutex; use std::borrow::Borrow; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index dde0d096..32fea1d5 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1 +1,15 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + pub(crate) mod lru; diff --git a/src/wasm.rs b/src/wasm.rs index 5d54ac61..d2042b22 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + #![cfg(target_arch = "wasm32")] use crate::db::{DataBaseBuilder, Database, DatabaseIter, ResultIter}; diff --git a/tests/macros-test/src/main.rs b/tests/macros-test/src/main.rs index af98aa63..da5e8e6e 100644 --- a/tests/macros-test/src/main.rs +++ b/tests/macros-test/src/main.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + fn main() {} #[cfg(test)] diff --git a/tests/slt/where_by_index.slt b/tests/slt/where_by_index.slt index c7ca1880..4b95c750 100644 --- a/tests/slt/where_by_index.slt +++ b/tests/slt/where_by_index.slt @@ -198,5 +198,70 @@ select * from t1 where c2 > 0 and c2 < 10; 0 1 9 6 7 8 +# unique covered +query I rowsort +select c1 from t1 where c1 < 10; +---- +1 +7 + +# unique covered with primary key projection +query II rowsort +select c1, id from t1 where c1 < 10; +---- +1 0 +7 6 + +statement ok +drop index t1.u_c1_index; + +# normal covered +query II rowsort +select c2 from t1 where c2 < 10 and c2 > 0; +---- +8 +9 + +statement ok +drop index t1.c2_index; + +# composite covered +query II rowsort +select c1, c2 from t1 where c1 < 10 and c1 > 0 and c2 >0 and c2 < 10; +---- +1 9 +7 8 + +# composite covered projection reorder +query II rowsort +select c2, c1 from t1 where c1 < 10 and c1 > 0 and c2 > 0 and c2 < 10; +---- +8 7 +9 1 + + +statement ok +drop table t1; + +statement ok +create table t_cover(id int primary key, c1 int, c2 int, c3 int); + +statement ok +insert into t_cover values + (1, 1, 10, 11), + (2, 2, 20, 21), + (3, 2, 22, 23), + (4, 3, 30, 31); + +statement ok +create index idx_cover on t_cover (c1, c2, c3); + +# composite index trailing columns cover (index columns > output columns) +query II rowsort +select c2, c3 from t_cover where c1 = 2; +---- +20 21 +22 23 + statement ok -drop table t1; \ No newline at end of file +drop table t_cover; diff --git a/tests/sqllogictest/src/lib.rs b/tests/sqllogictest/src/lib.rs index 6ab7d78b..2cc6a39d 100644 --- a/tests/sqllogictest/src/lib.rs +++ b/tests/sqllogictest/src/lib.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use kite_sql::db::{Database, ResultIter}; use kite_sql::errors::DatabaseError; use kite_sql::storage::rocksdb::RocksStorage; diff --git a/tests/sqllogictest/src/main.rs b/tests/sqllogictest/src/main.rs index 129ed284..39528205 100644 --- a/tests/sqllogictest/src/main.rs +++ b/tests/sqllogictest/src/main.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use clap::Parser; use kite_sql::db::DataBaseBuilder; use sqllogictest::Runner; diff --git a/tpcc/src/delivery.rs b/tpcc/src/delivery.rs index 42eecc7e..a5f33cec 100644 --- a/tpcc/src/delivery.rs +++ b/tpcc/src/delivery.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::load::DIST_PER_WARE; use crate::{TpccArgs, TpccError, TpccTest, TpccTransaction}; use chrono::Utc; diff --git a/tpcc/src/load.rs b/tpcc/src/load.rs index 8c0628e3..b76aef32 100644 --- a/tpcc/src/load.rs +++ b/tpcc/src/load.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::TpccError; use chrono::Utc; use indicatif::{ProgressBar, ProgressStyle}; diff --git a/tpcc/src/main.rs b/tpcc/src/main.rs index df6d9c1d..b741bbf2 100644 --- a/tpcc/src/main.rs +++ b/tpcc/src/main.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::delivery::DeliveryTest; use crate::load::Load; use crate::new_ord::NewOrdTest; diff --git a/tpcc/src/new_ord.rs b/tpcc/src/new_ord.rs index 790286a7..ec9d3939 100644 --- a/tpcc/src/new_ord.rs +++ b/tpcc/src/new_ord.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::load::{nu_rand, CUST_PER_DIST, DIST_PER_WARE, MAX_ITEMS, MAX_NUM_ITEMS}; use crate::{other_ware, TpccArgs, TpccError, TpccTest, TpccTransaction, ALLOW_MULTI_WAREHOUSE_TX}; use chrono::Utc; diff --git a/tpcc/src/order_stat.rs b/tpcc/src/order_stat.rs index 7ec2ce1c..e32595d2 100644 --- a/tpcc/src/order_stat.rs +++ b/tpcc/src/order_stat.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::load::{last_name, nu_rand, CUST_PER_DIST, DIST_PER_WARE}; use crate::{TpccArgs, TpccError, TpccTest, TpccTransaction}; use kite_sql::db::{DBTransaction, Statement}; diff --git a/tpcc/src/payment.rs b/tpcc/src/payment.rs index 37adce16..fb79aed6 100644 --- a/tpcc/src/payment.rs +++ b/tpcc/src/payment.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::load::{last_name, nu_rand, CUST_PER_DIST, DIST_PER_WARE}; use crate::{other_ware, TpccArgs, TpccError, TpccTest, TpccTransaction, ALLOW_MULTI_WAREHOUSE_TX}; use chrono::Utc; diff --git a/tpcc/src/rt_hist.rs b/tpcc/src/rt_hist.rs index 145783d8..21402115 100644 --- a/tpcc/src/rt_hist.rs +++ b/tpcc/src/rt_hist.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use ordered_float::OrderedFloat; use std::time::Duration; diff --git a/tpcc/src/slev.rs b/tpcc/src/slev.rs index ae8dd592..54347ccc 100644 --- a/tpcc/src/slev.rs +++ b/tpcc/src/slev.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use crate::load::DIST_PER_WARE; use crate::{TpccArgs, TpccError, TpccTest, TpccTransaction}; use kite_sql::db::{DBTransaction, Statement}; diff --git a/tpcc/src/utils.rs b/tpcc/src/utils.rs index 6b065713..2e9238dd 100644 --- a/tpcc/src/utils.rs +++ b/tpcc/src/utils.rs @@ -1,3 +1,17 @@ +// Copyright 2024 KipData/KiteSQL +// +// 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. + use rand::rngs::ThreadRng; use rand::Rng;