diff --git a/prql-java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java b/prql-java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java index 81fb2feebce7..5a8627d62c57 100644 --- a/prql-java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java +++ b/prql-java/java/src/test/java/org/prql/prql4j/PrqlCompilerTest.java @@ -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--")); @@ -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); } } diff --git a/prql-java/src/lib.rs b/prql-java/src/lib.rs index cc938a46efee..69be6e50be28 100644 --- a/prql-java/src/lib.rs +++ b/prql-java/src/lib.rs @@ -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)] @@ -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);