TableEngine and SqlHandler impl (#45)

* Impl TableEngine, bridge to storage

* Impl sql handler to process insert sql

* fix: minor changes and typo

* test: add datanode test

* test: add table-engine test

* fix: code style

* refactor: split out insert mod from sql and minor changes by CR

* refactor: replace with_context with context
This commit is contained in:
dennis zhuang
2022-06-17 11:36:49 +08:00
committed by GitHub
parent e03ac2fc2b
commit e78c015fc0
36 changed files with 1438 additions and 110 deletions

View File

@@ -14,9 +14,9 @@ pub use datatypes::data_type::ConcreteDataType;
pub use datatypes::schema::{ColumnSchema, Schema, SchemaRef};
pub use self::descriptors::{
ColumnDescriptor, ColumnDescriptorBuilder, ColumnFamilyDescriptor,
ColumnFamilyDescriptorBuilder, ColumnFamilyId, ColumnId, RegionDescriptor, RowKeyDescriptor,
RowKeyDescriptorBuilder,
gen_region_name, ColumnDescriptor, ColumnDescriptorBuilder, ColumnFamilyDescriptor,
ColumnFamilyDescriptorBuilder, ColumnFamilyId, ColumnId, RegionDescriptor, RegionId,
RowKeyDescriptor, RowKeyDescriptorBuilder,
};
pub use self::engine::{EngineContext, StorageEngine};
pub use self::metadata::RegionMeta;

View File

@@ -6,6 +6,14 @@ use crate::storage::{consts, ColumnSchema, ConcreteDataType};
pub type ColumnId = u32;
/// Id of column family, unique in each region.
pub type ColumnFamilyId = u32;
pub type RegionId = u32;
/// Default region name prefix
pub const REGION_PREFIX: &str = "r_";
#[inline]
pub fn gen_region_name(id: RegionId) -> String {
format!("{}{}", REGION_PREFIX, id)
}
// TODO(yingwen): Validate default value has same type with column, and name is a valid column name.
/// A [ColumnDescriptor] contains information to create a column.
@@ -52,6 +60,7 @@ pub struct ColumnFamilyDescriptor {
/// A [RegionDescriptor] contains information to create a region.
#[derive(Debug, Clone, PartialEq)]
pub struct RegionDescriptor {
pub id: RegionId,
/// Region name.
pub name: String,
/// Row key descriptor of this region.
@@ -286,4 +295,10 @@ mod tests {
.build();
assert_eq!(1, desc.columns.len());
}
#[test]
fn test_gen_region_name() {
assert_eq!("r_0", gen_region_name(0));
assert_eq!("r_99", gen_region_name(99));
}
}

View File

@@ -12,7 +12,7 @@ use crate::storage::region::Region;
/// Storage engine provides primitive operations to store and access data.
#[async_trait]
pub trait StorageEngine: Send + Sync + Clone {
pub trait StorageEngine: Send + Sync + Clone + 'static {
type Error: ErrorExt + Send + Sync;
type Region: Region;

View File

@@ -28,7 +28,7 @@ use crate::storage::snapshot::{ReadContext, Snapshot};
/// Chunks of rows in storage engine.
#[async_trait]
pub trait Region: Send + Sync + Clone {
pub trait Region: Send + Sync + Clone + 'static {
type Error: ErrorExt + Send + Sync;
type Meta: RegionMeta;
type WriteRequest: WriteRequest;
@@ -52,5 +52,5 @@ pub trait Region: Send + Sync + Clone {
}
/// Context for write operations.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct WriteContext {}

View File

@@ -13,7 +13,7 @@ pub trait WriteRequest: Send {
}
/// Put multiple rows.
pub trait PutOperation {
pub trait PutOperation: Send {
type Error: ErrorExt + Send + Sync;
fn new() -> Self;