Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: table options #2767

Merged
merged 47 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1cd4172
refactor: move parser into own crate
universalmind303 Mar 6, 2024
e154cbf
refactor: move parser into own crate
universalmind303 Mar 6, 2024
b80aff8
Merge branch 'main' into universalmind303/extract-parser
universalmind303 Mar 6, 2024
1a2a931
remove main
universalmind303 Mar 6, 2024
fec18cc
Merge branch 'universalmind303/extract-parser' of github.com:GlareDB/…
universalmind303 Mar 6, 2024
e9ecd2a
cleanup
universalmind303 Mar 6, 2024
2849edc
pr feedback
universalmind303 Mar 6, 2024
04c88c8
refactor: remove proptests (#2748)
universalmind303 Mar 6, 2024
932884e
wip: table options refactor
universalmind303 Mar 7, 2024
2652d61
wip
universalmind303 Mar 7, 2024
bb0ce70
wip
universalmind303 Mar 8, 2024
d3f03c4
wip
universalmind303 Mar 8, 2024
4335900
i think first pass is done
universalmind303 Mar 8, 2024
ace5fc1
wip
universalmind303 Mar 8, 2024
0f19436
get all tests passing, TODO: external schema
universalmind303 Mar 8, 2024
2502a61
add some docstrings
universalmind303 Mar 11, 2024
e85f623
remove validation from datasource
universalmind303 Mar 11, 2024
305a74f
fmt
universalmind303 Mar 11, 2024
d3a4c7c
fix the "columns" stuff
universalmind303 Mar 11, 2024
7ca5256
refactor(table options): serde (#2770)
universalmind303 Mar 12, 2024
5052e92
Merge branch 'universalmind303/table-options-refactor' of github.com:…
universalmind303 Mar 12, 2024
6e8d7c0
Merge branch 'main' of github.com:GlareDB/glaredb into universalmind3…
universalmind303 Mar 12, 2024
c46933d
pr feedback
universalmind303 Mar 12, 2024
c056a0e
get schema stuff working
universalmind303 Mar 12, 2024
4935cc3
refactor(table options): backwards compat for catalog (#2775)
universalmind303 Mar 12, 2024
bc17867
fmt
universalmind303 Mar 12, 2024
d9baec8
Merge branch 'universalmind303/table-options-refactor' of github.com:…
universalmind303 Mar 12, 2024
ae2c21f
wip
universalmind303 Mar 14, 2024
d3b03be
remove "datasource" stuff
universalmind303 Mar 14, 2024
691980e
revert more code
universalmind303 Mar 14, 2024
0e42b84
revert more code
universalmind303 Mar 14, 2024
8a62643
revert more code
universalmind303 Mar 14, 2024
2c178e0
clippy
universalmind303 Mar 14, 2024
ddf88ce
cleanup
universalmind303 Mar 14, 2024
918b94e
Merge branch 'main' into universalmind303/table-options-refactor
universalmind303 Mar 14, 2024
49494ca
cleanup
universalmind303 Mar 14, 2024
1fb7a26
revert more code
universalmind303 Mar 14, 2024
b243e41
Merge branch 'main' into universalmind303/table-options-refactor
universalmind303 Mar 14, 2024
5604c58
revert more code
universalmind303 Mar 14, 2024
93ea929
Merge branch 'universalmind303/table-options-refactor' of github.com:…
universalmind303 Mar 14, 2024
b7b6a58
tbl opts
universalmind303 Mar 14, 2024
45cf0dc
fixes
universalmind303 Mar 14, 2024
eefa93e
Merge branch 'main' of github.com:GlareDB/glaredb into universalmind3…
universalmind303 Mar 15, 2024
0513e84
pr feedback
universalmind303 Mar 15, 2024
9890312
pr feedback
universalmind303 Mar 15, 2024
c72af53
clippy
universalmind303 Mar 15, 2024
3bf7d5f
merge from main
universalmind303 Mar 27, 2024
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: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/metastore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ioutil = { path = "../ioutil" }
logutil = { path = "../logutil" }
protogen = { path = "../protogen" }
sqlbuiltins = { path = "../sqlbuiltins" }
datasources = { path = "../datasources" }
object_store_util = { path = "../object_store_util" }
pgrepr = { path = "../pgrepr" }
async-trait = { workspace = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/protogen/proto/metastore/catalog.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import "common/arrow.proto";

// The state of the catalog at some version.
message CatalogState {
// The version of the actual catalog implementation.
// This is incremented when there are incompatible changes to the physical
// catalog layout.
// Purposely set to a high number to avoid accidental collisions
optional uint32 catalog_version = 2047;

// Version of this catalog. Increments on every mutation.
uint64 version = 1;

Expand All @@ -50,12 +56,6 @@ message CatalogState {
// Metadata for the deployment.
DeploymentMetadata deployment = 3;
// next: 4

// The version of the actual catalog implementation.
// This is incremented when there are incompatible changes to the physical
// catalog layout.
// Purposely set to a high number to avoid accidental collisions
optional uint32 catalog_version = 2047;
}

// Metadata for the deployment.
Expand Down
1 change: 1 addition & 0 deletions crates/protogen/proto/metastore/options.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ message StorageOptions {
message TableOptionsV1 {
string name = 1;
bytes options = 2;
uint32 version = 3;
}

// Table options
Expand Down
22 changes: 5 additions & 17 deletions crates/protogen/src/metastore/types/options.rs
universalmind303 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl TryFrom<options::InternalColumnDefinition> for InternalColumnDefinition {
fn try_from(value: options::InternalColumnDefinition) -> Result<Self, Self::Error> {
let arrow_type: DataType = value.arrow_type.as_ref().required("arrow_type")?;


Ok(InternalColumnDefinition {
name: value.name,
nullable: value.nullable,
Expand Down Expand Up @@ -592,7 +591,6 @@ impl StorageOptions {
}
}


impl TryFrom<options::StorageOptions> for StorageOptions {
type Error = ProtoConvError;
fn try_from(value: options::StorageOptions) -> Result<Self, Self::Error> {
Expand All @@ -610,13 +608,14 @@ impl From<StorageOptions> for options::StorageOptions {
pub struct TableOptionsV1 {
pub name: String,
pub options: Vec<u8>,
pub version: u32,
}

pub trait TableOptionsImpl: Serialize + DeserializeOwned {
const NAME: &'static str;
const VERSION: u32 = 1;
}


impl Display for TableOptionsV1 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name)
Expand All @@ -634,6 +633,7 @@ impl TableOptionsV1 {
TableOptionsV1 {
name: S::NAME.to_string(),
options,
version: S::VERSION,
}
}

Expand Down Expand Up @@ -667,7 +667,6 @@ where
}
}


impl TryFrom<options::TableOptionsV1> for TableOptionsV1 {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsV1) -> Result<Self, Self::Error> {
Expand All @@ -677,6 +676,7 @@ impl TryFrom<options::TableOptionsV1> for TableOptionsV1 {
Ok(TableOptionsV1 {
options: values,
name,
version: value.version,
})
}
}
Expand All @@ -686,11 +686,11 @@ impl From<TableOptionsV1> for options::TableOptionsV1 {
options::TableOptionsV1 {
name: value.name,
options: value.options,
version: value.version,
}
}
}


#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TableOptionsV0 {
Debug(TableOptionsDebug),
Expand Down Expand Up @@ -800,7 +800,6 @@ impl TryFrom<&TableOptionsV1> for TableOptionsV0 {
fn try_from(value: &TableOptionsV1) -> Result<Self, Self::Error> {
let _v: serde_json::Value = serde_json::from_slice(&value.options).unwrap();


match value.name.as_ref() {
TableOptionsObjectStore::NAME => {
let obj_store: TableOptionsObjectStore = value.extract()?;
Expand Down Expand Up @@ -1031,7 +1030,6 @@ impl TableOptionsImpl for TableOptionsInternal {
const NAME: &'static str = "internal";
}


impl From<DFSchemaRef> for TableOptionsInternal {
fn from(value: DFSchemaRef) -> Self {
TableOptionsInternal {
Expand Down Expand Up @@ -1103,7 +1101,6 @@ impl TableOptionsImpl for TableOptionsPostgres {
const NAME: &'static str = "postgres";
}


impl TryFrom<options::TableOptionsPostgres> for TableOptionsPostgres {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsPostgres) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1143,7 +1140,6 @@ impl TableOptionsImpl for TableOptionsBigQuery {
const NAME: &'static str = "bigquery";
}


impl TryFrom<options::TableOptionsBigQuery> for TableOptionsBigQuery {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsBigQuery) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1184,7 +1180,6 @@ impl TableOptionsImpl for TableOptionsMysql {
const NAME: &'static str = "mysql";
}


impl TryFrom<options::TableOptionsMysql> for TableOptionsMysql {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsMysql) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1223,7 +1218,6 @@ impl TableOptionsImpl for TableOptionsLocal {
const NAME: &'static str = "local";
}


impl TryFrom<options::TableOptionsLocal> for TableOptionsLocal {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsLocal) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1355,7 +1349,6 @@ impl TableOptionsImpl for TableOptionsMongoDb {
const NAME: &'static str = "mongo";
}


impl TryFrom<options::TableOptionsMongo> for TableOptionsMongoDb {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsMongo) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1397,7 +1390,6 @@ impl TableOptionsImpl for TableOptionsExcel {
const NAME: &'static str = "excel";
}


impl TryFrom<options::TableOptionsExcel> for TableOptionsExcel {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsExcel) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1442,7 +1434,6 @@ impl TableOptionsImpl for TableOptionsSqlServer {
const NAME: &'static str = "sql_server";
}


impl TryFrom<options::TableOptionsSqlServer> for TableOptionsSqlServer {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsSqlServer) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1562,7 +1553,6 @@ impl TableOptionsImpl for TableOptionsSqlite {
const NAME: &'static str = "sqlite";
}


impl TryFrom<options::TableOptionsSqlite> for TableOptionsSqlite {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsSqlite) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -1644,12 +1634,10 @@ pub struct TableOptionsObjectStore {
pub schema_sample_size: Option<i64>,
}


impl TableOptionsImpl for TableOptionsObjectStore {
const NAME: &'static str = "object_store";
}


impl TryFrom<options::TableOptionsObjectStore> for TableOptionsObjectStore {
type Error = ProtoConvError;
fn try_from(value: options::TableOptionsObjectStore) -> Result<Self, Self::Error> {
Expand Down
1 change: 0 additions & 1 deletion crates/sqlexec/src/dispatch/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ use sqlbuiltins::functions::FunctionRegistry;
use super::{DispatchError, Result};

/// Dispatch to external tables and databases.
// TODO: add a `DatasourceRegistry` to the `ExternalDispatcher` to allow for dynamic datasources.
pub struct ExternalDispatcher<'a> {
catalog: &'a SessionCatalog,
// TODO: Remove need for this.
Expand Down
18 changes: 12 additions & 6 deletions crates/sqlexec/src/planner/session_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,16 +966,22 @@ impl<'a> SessionPlanner<'a> {
.into_iter()
.map(|coll| -> Result<Field, PlanError> {
// check if there is a NOT NULL constraint
let is_nullable = !coll
let has_not_null_constraint = coll
universalmind303 marked this conversation as resolved.
Show resolved Hide resolved
.options
.into_iter()
.any(|k| matches!(k.option, ColumnOption::NotNull));

Ok(Field::new(
coll.name.to_string(),
convert_data_type(&coll.data_type)?,
is_nullable,
))
if has_not_null_constraint {
Err(PlanError::String(
"'NOT NULL' constraint is not supported".to_string(),
))
} else {
Ok(Field::new(
coll.name.to_string(),
convert_data_type(&coll.data_type)?,
true,
))
}
})
.collect::<Result<Vec<_>, PlanError>>()?;
Ok::<_, PlanError>(Schema::new(fields))
Expand Down