Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf binary
13 changes: 12 additions & 1 deletion codegen/src/common/model/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use indexmap::IndexMap;
use std::collections::HashMap;

use crate::common::model::index::Index;
use crate::common::model::{GeneratorType, IndexBackend};
use crate::common::model::{ColumnSlotIdType, ColumnarFieldConfig, ColumnarIndex, GeneratorType, IndexBackend};
use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::spanned::Spanned;
Expand All @@ -17,6 +17,9 @@ pub struct Columns {
pub columns_map: HashMap<Ident, TokenStream>,
pub field_positions: HashMap<Ident, usize>,
pub indexes: IndexMap<Ident, Index>,
pub columnar_fields: IndexMap<Ident, ColumnarFieldConfig>,
pub columnar_indexes: IndexMap<Ident, ColumnarIndex>,
pub column_slot_id: ColumnSlotIdType,
pub primary_keys: Vec<Ident>,
pub primary_index_backend: IndexBackend,
pub generator_type: GeneratorType,
Expand All @@ -30,6 +33,7 @@ pub struct Row {
pub gen_type: GeneratorType,
pub optional: bool,
pub index_backend: Option<IndexBackend>,
pub columnar: Option<ColumnarFieldConfig>,
}

impl Columns {
Expand All @@ -40,6 +44,7 @@ impl Columns {
let mut pk = vec![];
let mut gen_type = None;
let mut primary_index_backend = None;
let mut columnar_fields = IndexMap::new();

for (pos, row) in rows.into_iter().enumerate() {
let type_ = &row.type_;
Expand All @@ -53,6 +58,9 @@ impl Columns {
};
columns_map.insert(row.name.clone(), type_);
field_positions.insert(row.name.clone(), pos);
if let Some(config) = row.columnar {
columnar_fields.insert(row.name.clone(), config);
}

if row.is_primary_key {
if let Some(t) = gen_type {
Expand Down Expand Up @@ -90,6 +98,9 @@ impl Columns {
is_sized: sized,
columns_map,
indexes: Default::default(),
columnar_fields,
columnar_indexes: Default::default(),
column_slot_id: Default::default(),
primary_keys: pk,
primary_index_backend: primary_index_backend.unwrap_or_default(),
generator_type: gen_type.expect("set"),
Expand Down
63 changes: 63 additions & 0 deletions codegen/src/common/model/columnar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use proc_macro2::Ident;

pub const DEFAULT_COLUMNAR_CHUNK_ROWS: usize = 65_536;

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum ColumnSlotIdType {
U8,
U16,
#[default]
U32,
U64,
}

impl ColumnSlotIdType {
pub(crate) fn type_name(self) -> &'static str {
match self {
Self::U8 => "ColumnSlotId8",
Self::U16 => "ColumnSlotId16",
Self::U32 => "ColumnSlotId32",
Self::U64 => "ColumnSlotId64",
}
}
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum ColumnCompression {
#[default]
None,
}

impl ColumnCompression {
pub(crate) fn name(self) -> &'static str {
match self {
Self::None => "none",
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ColumnarFieldConfig {
pub chunk_rows: Option<usize>,
pub compression: ColumnCompression,
}

impl Default for ColumnarFieldConfig {
fn default() -> Self {
Self {
chunk_rows: None,
compression: ColumnCompression::None,
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnarIndex {
pub name: Ident,
pub cluster_by: Vec<Ident>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ColumnarIndexes {
pub indexes: indexmap::IndexMap<Ident, ColumnarIndex>,
}
17 changes: 16 additions & 1 deletion codegen/src/common/model/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
use proc_macro2::Ident;

#[derive(Debug, Default)]
use crate::common::model::{ColumnSlotIdType, DEFAULT_COLUMNAR_CHUNK_ROWS};

#[derive(Debug)]
pub struct Config {
pub page_size: Option<u32>,
pub row_derives: Vec<Ident>,
pub columnar_slot_id: ColumnSlotIdType,
pub columnar_chunk_rows: usize,
}

impl Default for Config {
fn default() -> Self {
Self {
page_size: None,
row_derives: Vec::new(),
columnar_slot_id: ColumnSlotIdType::default(),
columnar_chunk_rows: DEFAULT_COLUMNAR_CHUNK_ROWS,
}
}
}
5 changes: 5 additions & 0 deletions codegen/src/common/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod column;
mod columnar;
mod config;
mod index;
pub mod operation;
Expand All @@ -7,6 +8,10 @@ mod primary_key;
mod queries;

pub use column::{Columns, Row};
pub use columnar::{
ColumnCompression, ColumnSlotIdType, ColumnarFieldConfig, ColumnarIndex, ColumnarIndexes,
DEFAULT_COLUMNAR_CHUNK_ROWS,
};
pub use config::Config;
pub use index::{Index, IndexBackend};
pub use operation::Operation;
Expand Down
Loading
Loading