mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-18 22:10:42 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user