Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[package]
Expand All @@ -10,7 +8,6 @@ edition = "2021"
[lib]
doctest = false


[dependencies]
log = "^0.4"
sqlparser = "0.34.0"
Expand All @@ -33,6 +30,7 @@ tokio-process = "0.2.5"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
async-trait = "0.1.68"
integer-encoding = "3.0.4"

[dev-dependencies]
ctor = "0.2.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the provided code patch, here are some observations and suggestions for improvement:

  • There is no actual code in the patch, it only shows changes made to the project's Cargo.toml file.
  • The removal of two blank lines at the beginning of the file does not affect functionality but can improve readability.
  • The removal of the doctest option from the [lib] section does not have any impact if there were no doctests in the library. Otherwise, it should be investigated why this change was made.
  • It is recommended to add version numbers for all dependencies to ensure consistent builds over time. It's good to see that most dependencies already have a version specified.
  • The addition of the integer-encoding dependency looks valid based on its version and purpose, assuming it is needed in the codebase.
  • The [dev-dependencies] section contains only one package, which is used during development, so it does not affect production builds. However, it's important to make sure that all development dependencies are not causing security risks or any performance issues.

Overall, the changes in the code patch seem reasonable and appropriate, but without more context, it's hard to provide a more precise review.

Expand Down
5 changes: 3 additions & 2 deletions src/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ mod select;
use std::collections::HashMap;

use crate::{
catalog::{CatalogRef, TableRefId},
catalog::CatalogRef,
expression::ScalarExpression,
planner::LogicalPlan,
};

use anyhow::Result;
use sqlparser::ast::Statement;
use crate::types::TableId;

pub struct BinderContext {
catalog: CatalogRef,
bind_table: HashMap<String, TableRefId>,
bind_table: HashMap<String, TableId>,
aliases: HashMap<String, ScalarExpression>,
group_by_exprs: Vec<ScalarExpression>,
agg_calls: Vec<ScalarExpression>,
Expand Down
13 changes: 7 additions & 6 deletions src/binder/select.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{borrow::Borrow, sync::Arc};

use crate::{
catalog::{ColumnRefId, DEFAULT_DATABASE_NAME, DEFAULT_SCHEMA_NAME},
catalog::ColumnRefId,
expression::ScalarExpression,
planner::{
logical_select_plan::LogicalSelectPlan,
Expand All @@ -22,6 +22,7 @@ use sqlparser::ast::{
Expr, Ident, Join, JoinConstraint, JoinOperator, Offset, OrderByExpr, Query, Select,
SelectItem, SetExpr, TableFactor, TableWithJoins,
};
use crate::catalog::{DEFAULT_DATABASE_NAME, DEFAULT_SCHEMA_NAME};

impl Binder {
pub(super) fn bind_query(&mut self, query: &Query) -> Result<LogicalSelectPlan> {
Expand Down Expand Up @@ -127,7 +128,7 @@ impl Binder {
.map(|ident| Ident::new(ident.value.to_lowercase()))
.collect_vec();

let (database, schema, mut table): (&str, &str, &str) = match obj_name.as_slice() {
let (_database, _schema, mut table): (&str, &str, &str) = match obj_name.as_slice() {
[table] => (DEFAULT_DATABASE_NAME, DEFAULT_SCHEMA_NAME, &table.value),
[schema, table] => (DEFAULT_DATABASE_NAME, &schema.value, &table.value),
[database, schema, table] => (&database.value, &schema.value, &table.value),
Expand All @@ -147,7 +148,7 @@ impl Binder {
let table_ref_id = self
.context
.catalog
.get_table_id_by_name(database, schema, table)
.get_table_id_by_name(table)
.ok_or_else(|| anyhow::Error::msg(format!("bind table {}", table)))?;

self.context.bind_table.insert(table.into(), table_ref_id);
Expand Down Expand Up @@ -198,7 +199,7 @@ impl Binder {
fn bind_all_column_refs(&mut self) -> Result<Vec<ScalarExpression>> {
let mut exprs = vec![];
for ref_id in self.context.bind_table.values().cloned().collect_vec() {
let table = self.context.catalog.get_table(&ref_id).unwrap();
let table = self.context.catalog.get_table(ref_id).unwrap();
for (col_id, col) in &table.get_all_columns() {
let column_ref_id = ColumnRefId::from_table(ref_id, *col_id);
// self.record_regular_table_column(
Expand All @@ -209,8 +210,8 @@ impl Binder {
// );
let expr = ScalarExpression::ColumnRef {
column_ref_id,
primary_key: col.is_primary(),
desc: col.desc().clone(),
primary_key: col.desc.is_primary(),
desc: col.desc.clone(),
};
exprs.push(expr);
}
Expand Down
107 changes: 35 additions & 72 deletions src/catalog/column.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
use crate::types::{ColumnIdT, DataType};
use crate::types::{ColumnId, DataType, IdGenerator};

/// The descriptor of a column.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnDesc {
column_datatype: DataType,
is_primary: bool,
#[derive(Clone)]
pub struct Column {
pub id: ColumnId,
pub name: String,
pub desc: ColumnDesc,
}

impl ColumnDesc {
pub(crate) const fn new(column_datatype: DataType, is_primary: bool) -> ColumnDesc {
ColumnDesc {
column_datatype,
is_primary,
impl Column {
pub(crate) fn new(
column_name: String,
column_desc: ColumnDesc,
) -> Column {
Column {
id: IdGenerator::build(),
name: column_name,
desc: column_desc,
}
}

pub(crate) fn is_primary(&self) -> bool {
self.is_primary
}

pub(crate) fn set_primary(&mut self, is_primary: bool) {
self.is_primary = is_primary;
}

pub(crate) fn is_nullable(&self) -> bool {
self.column_datatype.is_nullable()
}

pub(crate) fn get_datatype(&self) -> DataType {
self.column_datatype.clone()
pub(crate) fn datatype(&self) -> &DataType {
&self.desc.column_datatype
}
}

Expand All @@ -43,56 +35,31 @@ impl DataType {
}
}

/// Column catalog
/// The descriptor of a column.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Column {
id: ColumnIdT,
name: String,
desc: ColumnDesc,
pub struct ColumnDesc {
column_datatype: DataType,
is_primary: bool,
}

impl Column {
pub(crate) fn new(
column_id: ColumnIdT,
column_name: String,
column_desc: ColumnDesc,
) -> Column {
Column {
id: column_id,
name: column_name,
desc: column_desc,
impl ColumnDesc {
pub(crate) const fn new(column_datatype: DataType, is_primary: bool) -> ColumnDesc {
ColumnDesc {
column_datatype,
is_primary,
}
}

pub(crate) fn id(&self) -> ColumnIdT {
self.id
}
pub fn set_id(&mut self, column_id: ColumnIdT) {
self.id = column_id
}

pub(crate) fn name(&self) -> &str {
&self.name
}

pub fn desc(&self) -> &ColumnDesc {
&self.desc
}

pub fn datatype(&self) -> DataType {
self.desc.column_datatype.clone()
}

pub(crate) fn set_primary(&mut self, is_primary: bool) {
self.desc.set_primary(is_primary)
}

pub(crate) fn is_primary(&self) -> bool {
self.desc.is_primary()
self.is_primary
}

pub(crate) fn is_nullable(&self) -> bool {
self.desc.is_nullable()
self.column_datatype.is_nullable()
}

pub(crate) fn get_datatype(&self) -> DataType {
self.column_datatype.clone()
}
}

Expand All @@ -104,16 +71,12 @@ mod tests {
#[test]
fn test_column_catalog() {
let mut col_catalog = Column::new(
0,
"test".to_string(),
DataTypeKind::Int(None).not_null().to_column(),
);

assert_eq!(col_catalog.id(), 0);
assert_eq!(col_catalog.is_primary(), false);
assert_eq!(col_catalog.is_nullable(), false);
assert_eq!(col_catalog.name(), "test");
col_catalog.set_primary(true);
assert_eq!(col_catalog.is_primary(), true);
assert_eq!(col_catalog.desc.is_primary(), false);
assert_eq!(col_catalog.desc.is_nullable(), false);
assert_eq!(col_catalog.name, "test");
}
}
121 changes: 0 additions & 121 deletions src/catalog/database.rs

This file was deleted.

Loading