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

aligning names to sqlparser convention #250

Merged
merged 2 commits into from
Jan 16, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.0] - 2024-01-15
### Changed
- aligning Translators names to the sqlparser convention. Allowing only for compact filenames e.g. (filename: postgresql, tranlator: PostgreSqlTranslator, dialect (sqlparser): PostgreSqlDialect, etc.) [#250](https://github.com/Qrlew/qrlew/pull/250)

## [0.8.1] - 2024-01-15
### Changed
- Does not prevent fields from not being in the GROUP BY [#249](https://github.com/Qrlew/qrlew/issues/249)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Nicolas Grislain <ng@sarus.tech>"]
name = "qrlew"
version = "0.8.1"
version = "0.9.0"
edition = "2021"
description = "Sarus Qrlew Engine"
documentation = "https://docs.rs/qrlew"
Expand Down
2 changes: 1 addition & 1 deletion src/dialect_translation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub mod hive;
#[cfg(feature = "mssql")]
pub mod mssql;
pub mod mysql;
pub mod postgres;
pub mod postgresql;
pub mod sqlite;

// TODO: Add translatio errors
Expand Down
16 changes: 8 additions & 8 deletions src/dialect_translation/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use sqlparser::{
dialect::MsSqlDialect,
};
#[derive(Clone, Copy)]
pub struct MSSQLTranslator;
pub struct MsSqlTranslator;

impl RelationToQueryTranslator for MSSQLTranslator {
impl RelationToQueryTranslator for MsSqlTranslator {
/// Identifiers are back quoted
fn identifier(&self, value: &expr::Identifier) -> Vec<ast::Ident> {
let quoting_char: char = '"';
Expand Down Expand Up @@ -246,7 +246,7 @@ impl RelationToQueryTranslator for MSSQLTranslator {
}
}

impl QueryToRelationTranslator for MSSQLTranslator {
impl QueryToRelationTranslator for MsSqlTranslator {
type D = MsSqlDialect;

fn dialect(&self) -> Self::D {
Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {

let relation = Relation::try_from(With::with(&parse(query).unwrap(), &relations)).unwrap();

let rel_with_traslator = RelationWithTranslator(&relation, MSSQLTranslator);
let rel_with_traslator = RelationWithTranslator(&relation, MsSqlTranslator);
let translated_query = &ast::Query::from(rel_with_traslator).to_string()[..];
println!("{}", translated_query);

Expand All @@ -407,7 +407,7 @@ mod tests {

let relation = Relation::try_from(With::with(&parse(query).unwrap(), &relations)).unwrap();

let rel_with_traslator = RelationWithTranslator(&relation, MSSQLTranslator);
let rel_with_traslator = RelationWithTranslator(&relation, MsSqlTranslator);
let translated_query = &ast::Query::from(rel_with_traslator).to_string()[..];
println!("{}", translated_query);

Expand All @@ -429,7 +429,7 @@ mod tests {

let relation = Relation::try_from(With::with(&query, &relations)).unwrap();

let rel_with_traslator = RelationWithTranslator(&relation, MSSQLTranslator);
let rel_with_traslator = RelationWithTranslator(&relation, MsSqlTranslator);
let translated_query = &ast::Query::from(rel_with_traslator).to_string()[..];
println!("{}", translated_query);

Expand Down Expand Up @@ -467,7 +467,7 @@ mod tests {
.input(table.clone())
.build(),
);
let rel_with_traslator = RelationWithTranslator(map.as_ref(), MSSQLTranslator);
let rel_with_traslator = RelationWithTranslator(map.as_ref(), MsSqlTranslator);
let query = ast::Query::from(rel_with_traslator);
let translated = r#"
WITH map_1 (field_li80) AS (SELECT LOG("a") AS field_li80 FROM "table") SELECT * FROM "map_1"
Expand Down Expand Up @@ -496,7 +496,7 @@ mod tests {
let query = ast::Query::from(map.as_ref());
print!("NOT TRANSLATED: \n{}\n", query);

let translator = MSSQLTranslator;
let translator = MsSqlTranslator;
let rel = map.as_ref();
let rel_with_traslator = RelationWithTranslator(rel, translator);
let query = ast::Query::from(rel_with_traslator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use sqlparser::{ast, dialect::PostgreSqlDialect};

use crate::sql::{Error, Result};
#[derive(Clone, Copy)]
pub struct PostgresTranslator;
pub struct PostgresSqlTranslator;

impl RelationToQueryTranslator for PostgresTranslator {
impl RelationToQueryTranslator for PostgresSqlTranslator {
fn first(&self, expr: &expr::Expr) -> ast::Expr {
ast::Expr::from(expr)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl RelationToQueryTranslator for PostgresTranslator {
}
}

impl QueryToRelationTranslator for PostgresTranslator {
impl QueryToRelationTranslator for PostgresSqlTranslator {
type D = PostgreSqlDialect;

fn dialect(&self) -> Self::D {
Expand All @@ -156,7 +156,7 @@ mod tests {

#[test]
fn test_query() -> Result<()> {
let translator = PostgresTranslator;
let translator = PostgresSqlTranslator;
let query_str = "SELECT POSITION('o' IN z) AS col FROM table_2";
let query = parse_with_dialect(query_str, translator.dialect())?;
println!("{:?}", query);
Expand All @@ -181,7 +181,7 @@ mod tests {
let relations = Hierarchy::from([(["schema", "table"], Arc::new(table))]);

let query_str = "SELECT log(table.d + 1) FROM schema.table";
let translator = PostgresTranslator;
let translator = PostgresSqlTranslator;
let query = parse_with_dialect(query_str, translator.dialect())?;
let query_with_relation = QueryWithRelations::new(&query, &relations);
let relation = Relation::try_from((query_with_relation, translator))?;
Expand Down
10 changes: 5 additions & 5 deletions src/io/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{
env, fmt, ops::Deref, process::Command, str::FromStr, sync::Arc, sync::Mutex, thread, time,
};

use crate::dialect_translation::mssql::MSSQLTranslator;
use crate::dialect_translation::mssql::MsSqlTranslator;

const DB: &str = "qrlew-mssql-test";
const PORT: u16 = 1433;
Expand Down Expand Up @@ -322,7 +322,7 @@ impl DatabaseTrait for Database {

fn create_table(&mut self, table: &Table) -> Result<usize> {
let rt = tokio::runtime::Runtime::new().unwrap();
let translator = MSSQLTranslator;
let translator = MsSqlTranslator;
let create_table_query = &table.create(translator).to_string();
let query = sqlx::query(&create_table_query[..]);
let res = rt.block_on(async_execute(query, &self.pool))?;
Expand All @@ -333,7 +333,7 @@ impl DatabaseTrait for Database {
let rt = tokio::runtime::Runtime::new().unwrap();
let mut rng = StdRng::seed_from_u64(DATA_GENERATION_SEED);
let size = Database::MAX_SIZE.min(table.size().generate(&mut rng) as usize);
let ins_stat = &table.insert("@p", MSSQLTranslator).to_string();
let ins_stat = &table.insert("@p", MsSqlTranslator).to_string();

for _ in 1..size {
let structured: value::Struct =
Expand Down Expand Up @@ -620,8 +620,8 @@ mod tests {
.build();
let mut rng = StdRng::seed_from_u64(DATA_GENERATION_SEED);

let ins_stat = &table.insert("@p", MSSQLTranslator).to_string();
let create_stat = &table.create(MSSQLTranslator).to_string();
let ins_stat = &table.insert("@p", MsSqlTranslator).to_string();
let create_stat = &table.create(MsSqlTranslator).to_string();

//let new_ins = "INSERT INTO table_2 (x) VALUES (@p1)".to_string();
println!("{}\n", create_stat);
Expand Down
6 changes: 3 additions & 3 deletions src/io/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
value::{self, Value},
DataTyped,
},
dialect_translation::postgres::PostgresTranslator,
dialect_translation::postgresql::PostgresSqlTranslator,
namer,
relation::{Table, Variant as _},
};
Expand Down Expand Up @@ -204,14 +204,14 @@ impl DatabaseTrait for Database {

fn create_table(&mut self, table: &Table) -> Result<usize> {
let mut connection = self.pool.get()?;
Ok(connection.execute(&table.create(PostgresTranslator).to_string(), &[])? as usize)
Ok(connection.execute(&table.create(PostgresSqlTranslator).to_string(), &[])? as usize)
}

fn insert_data(&mut self, table: &Table) -> Result<()> {
let mut rng = StdRng::seed_from_u64(DATA_GENERATION_SEED);
let size = Database::MAX_SIZE.min(table.size().generate(&mut rng) as usize);
let mut connection = self.pool.get()?;
let statement = connection.prepare(&table.insert("$", PostgresTranslator).to_string())?;
let statement = connection.prepare(&table.insert("$", PostgresSqlTranslator).to_string())?;
for _ in 0..size {
let structured: value::Struct =
table.schema().data_type().generate(&mut rng).try_into()?;
Expand Down
4 changes: 2 additions & 2 deletions src/relation/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
use crate::{
ast,
data_type::{DataType, DataTyped},
dialect_translation::{postgres::PostgresTranslator, RelationToQueryTranslator},
dialect_translation::{postgresql::PostgresSqlTranslator, RelationToQueryTranslator},
expr::{identifier::Identifier, Expr},
visitor::Acceptor,
};
Expand Down Expand Up @@ -428,7 +428,7 @@ impl<'a, T: RelationToQueryTranslator> Visitor<'a, ast::Query> for FromRelationV
/// Based on the FromRelationVisitor implement the From trait
impl From<&Relation> for ast::Query {
fn from(value: &Relation) -> Self {
let dialect_translator = PostgresTranslator;
let dialect_translator = PostgresSqlTranslator;
value.accept(FromRelationVisitor::new(dialect_translator))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/sql/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
},
tokenizer::Tokenizer,
visitor::{Acceptor, Dependencies, Visited},
dialect_translation::{QueryToRelationTranslator, postgres::PostgresTranslator},
dialect_translation::{QueryToRelationTranslator, postgresql::PostgresSqlTranslator},
types::And, display::Dot
};
use itertools::Itertools;
Expand Down Expand Up @@ -691,7 +691,7 @@ impl<'a> TryFrom<QueryWithRelations<'a>> for Relation {
let query_names = query.accept(IntoQueryNamesVisitor);
// Visit for conversion
query
.accept(TryIntoRelationVisitor::new(relations, query_names, PostgresTranslator))
.accept(TryIntoRelationVisitor::new(relations, query_names, PostgresSqlTranslator))
.map(|r| r.as_ref().clone())
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use qrlew::io::sqlite;
use qrlew::{
ast,
dialect_translation::{
postgres::PostgresTranslator, RelationToQueryTranslator, RelationWithTranslator,
postgresql::PostgresSqlTranslator, RelationToQueryTranslator, RelationWithTranslator,
},
expr,
io::{postgresql, Database},
Expand Down Expand Up @@ -287,7 +287,7 @@ const QUERIES_FOR_MSSQL: &[&str] = &[
fn test_on_mssql() {
// In this test we construct relations from QUERIES and we execute
// the translated queries
use qrlew::dialect_translation::mssql::MSSQLTranslator;
use qrlew::dialect_translation::mssql::MsSqlTranslator;

let mut database = mssql::test_database();
println!("database {} = {}", database.name(), database.relations());
Expand All @@ -296,7 +296,7 @@ fn test_on_mssql() {
}
for &query in QUERIES_FOR_MSSQL.iter() {
println!("TESTING QUERY: {}", query);
test_execute(&mut database, query, MSSQLTranslator);
test_execute(&mut database, query, MsSqlTranslator);
}
}

Expand Down