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

Support Metadata trait #1096

Merged
merged 28 commits into from
Apr 2, 2023
Merged

Support Metadata trait #1096

merged 28 commits into from
Apr 2, 2023

Conversation

devgony
Copy link
Collaborator

@devgony devgony commented Feb 18, 2023

Goal

  • Support Metadata trait
  • Metadata uses Schemaless so that storage developer can put anything in it but basically it contains CREATED field of Table and Index

Todo

  • Implement Metadata trait
  • remove CREATED from GLUE_OBJECTS of core
  • split test case of CREATED to generate_metadata_tests

Remove Store trait related cfg features, (gluesql#1091)

Enable all by default.

Compile time feature control causes too much management cost.
We already have test cases in test-suite splitted based on store trait features.

Support `values` query in AST builder (gluesql#1041)

Currently, ASTBuilder does not support Values Query yet.
This PR supports Values Query in ASTBuilder

e.g.
let actual = values(vec!["1, 'a'", "2, 'b'"])
    .order_by(vec!["column1 desc"])
    .build();
let expected = "VALUES(1, 'a'), (2, 'b') ORDER BY column1 desc";
@coveralls
Copy link

coveralls commented Mar 6, 2023

Pull Request Test Coverage Report for Build 4586977286

  • 97 of 98 (98.98%) changed or added relevant lines in 8 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+2.0e**-05%**) to 98.858%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/src/executor/fetch.rs 25 26 96.15%
Files with Coverage Reduction New Missed Lines %
core/src/executor/validate.rs 1 99.24%
Totals Coverage Status
Change from base Build 4552438461: 2.0e-05%
Covered Lines: 40605
Relevant Lines: 41074

💛 - Coveralls

@devgony devgony marked this pull request as ready for review March 11, 2023 07:43
@devgony devgony requested review from panarch and ever0de and removed request for panarch March 11, 2023 07:43
@devgony devgony added the enhancement New feature or request label Mar 11, 2023
@ever0de ever0de requested a review from panarch March 11, 2023 07:44
@@ -68,21 +72,52 @@ impl Store for MemoryStorage {
}
}

#[async_trait(?Send)]
impl Metadata for MemoryStorage {
async fn scan_meta(&self) -> HashMap<String, Value> {
Copy link
Member

Choose a reason for hiding this comment

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

async function scan_metadata(&self) -> Result<Box<dyn Iterator<Item = Result<(String, Value)>>>>

Copy link
Member

Choose a reason for hiding this comment

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

it looks that we can simply use HashMap<String, Value> rather than Value.

@panarch panarch self-requested a review March 18, 2023 08:14
pub struct MemoryStorage {
pub id_counter: i64,
pub items: HashMap<String, Item>,
pub metadata: HashMap<String, Value>,
Copy link
Member

Choose a reason for hiding this comment

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

pub metadata: HashMap<String, HashMap<String, Value>>,

this would be more precise..?

Comment on lines 1 to 2
pub mod table;
pub use table::table;
Copy link
Member

Choose a reason for hiding this comment

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

These can provide two different ways to use module.

Like other modules we are using,
ref. https://github.com/gluesql/gluesql/blob/main/test-suite/src/data_type/mod.rs

How about only using pub mod table;?


pub trait GStoreMut: StoreMut + IndexMut + AlterTable + Transaction {}
impl<S: StoreMut + IndexMut + AlterTable + Transaction> GStoreMut for S {}

pub use {
self::metadata::{MetaIter, Metadata},
Copy link
Member

Choose a reason for hiding this comment

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

Like other modules, alter_table, data_row ..
we can omit self::

Comment on lines 214 to 231
let meta = table_metas.iter().find_map(|(table_name, hash_map)| {
if table_name == &schema.table_name {
Some(Value::Map(hash_map.clone()))
} else {
None
}
});
let table_row = HashMap::from([
("OBJECT_NAME".to_owned(), Value::Str(schema.table_name)),
("OBJECT_TYPE".to_owned(), Value::Str("TABLE".to_owned())),
]);

let table_rows = match meta {
Some(Value::Map(meta)) => {
table_row.into_iter().chain(meta).collect()
}
_ => table_row,
};
Copy link
Member

Choose a reason for hiding this comment

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

It looks that we can reduce use of collect.

let meta = table_metas
    .iter()
    .find_map(|(table_name, hash_map)| {
        (table_name == &schema.table_name).then(|| hash_map.clone())
    })
    .unwrap_or_default();

let table_rows = [
    ("OBJECT_NAME".to_owned(), Value::Str(schema.table_name)),
    ("OBJECT_TYPE".to_owned(), Value::Str("TABLE".to_owned())),
]
.into_iter()
.chain(meta);

@@ -71,18 +75,30 @@ impl Store for MemoryStorage {
#[async_trait(?Send)]
impl StoreMut for MemoryStorage {
async fn insert_schema(&mut self, schema: &Schema) -> Result<()> {
let created = HashMap::from([
("OBJECT_TYPE".to_owned(), Value::Str("TABLE".to_owned())),
Copy link
Member

Choose a reason for hiding this comment

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

This would not be necessary because which the same OBJECT_TYPE property is being used in execution layer.

Copy link
Collaborator Author

@devgony devgony Mar 19, 2023

Choose a reason for hiding this comment

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

I removed OBJECT_TYPE in this PR but it may be needed if we implement metadata of index later since only OBJECT_NAME is used as a key here.
Just in case TABLE_NAME and INDEX_NAME are identical (but object_types are different), both OBJECT_NAME and OBJECT_TYPE should be a key
Or need some separated stored area between table and index

@panarch panarch self-requested a review April 2, 2023 05:11
Copy link
Member

@panarch panarch left a comment

Choose a reason for hiding this comment

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

This is great!
All looks nice 👍 Thanks a lot 👍 👍

@panarch panarch merged commit a249626 into gluesql:main Apr 2, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants