Skip to content

Commit

Permalink
Use target rather than dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Mar 1, 2023
1 parent baf1e41 commit 1b3f46f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class PrqlCompilerTest {
@Test
public void compile() throws Exception {
String found = PrqlCompiler.toSql("from table", "mysql", true, true);
String found = PrqlCompiler.toSql("from table", "sql.mysql", true, true);

// remove signature
found = found.substring(0, found.indexOf("\n\n--"));
Expand All @@ -19,6 +19,6 @@ public void compile() throws Exception {

@Test(expected = Exception.class)
public void compileWithError() throws Exception {
PrqlCompiler.toSql("from table | filter id >> 1", "mysql", true, true);
PrqlCompiler.toSql("from table | filter id >> 1", "sql.mysql", true, true);
}
}
27 changes: 6 additions & 21 deletions prql-java/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use jni::objects::{JClass, JString};
use jni::sys::{jboolean, jstring};
use jni::JNIEnv;
use prql_compiler::sql::Dialect;
use prql_compiler::{json, pl_to_prql, prql_to_pl, ErrorMessages, Options, Target};
use std::str::FromStr;

#[no_mangle]
#[allow(non_snake_case)]
Expand All @@ -18,28 +18,13 @@ pub extern "system" fn Java_org_prql_prql4j_PrqlCompiler_toSql(
.get_string(query)
.expect("Couldn't get java string!")
.into();
let target_dialect: String = if let Ok(target_name) = env.get_string(target) {
target_name.into()
} else {
"sql.generic".to_owned()
};
let prql_target = match target_dialect.as_str() {
"sql.ansi" => Dialect::Ansi,
"sql.bigquery" => Dialect::BigQuery,
"sql.clickhouse" => Dialect::ClickHouse,
"sql.duckdb" => Dialect::DuckDb,
"sql.generic" => Dialect::Generic,
"sql.hive" => Dialect::Hive,
"sql.mssql" => Dialect::MsSql,
"sql.mysql" => Dialect::MySql,
"sql.postgres" => Dialect::PostgreSql,
"sql.sqlite" => Dialect::SQLite,
"sql.snowflake" => Dialect::Snowflake,
_ => Dialect::Generic,
};
let target_str: String = (env.get_string(target))
.expect("Couldn't get java string")
.into();
let prql_dialect: Target = Target::from_str(&target_str).unwrap_or(Target::Sql(None));
let opt = Options {
format: format != 0,
target: Target::Sql(Some(prql_target)),
target: prql_dialect,
signature_comment: signature != 0,
};
let result = prql_compiler::compile(&prql_query, &opt);
Expand Down

0 comments on commit 1b3f46f

Please sign in to comment.