From 4f810ead2e725f1337abdd9830c5d9242fba2bf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Mur=20Er=C5=BEen?= Date: Wed, 25 Jan 2023 22:06:59 +0100 Subject: [PATCH] Revert "fix" This reverts commit ffac2e369643cd32ae0b5d375c1de2951227ef3f. --- src/main.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9d32f7e..f58f250 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use std::io::prelude::*; use std::{fs, io}; use clap::{Parser, ValueEnum}; -use prql_compiler::{compile, ErrorMessages}; +use prql_compiler::compile; cfg_if::cfg_if! { if #[cfg(feature = "datafusion")] { @@ -227,7 +227,7 @@ fn main() -> Result<()> { if args.no_exec || (database == "" && args.from.len() == 0 && !args.sql) { let sql = get_sql_from_query(&query)?; - println!("{sql}"); + println!("{}", &sql); } else { let mut found_backend = false; @@ -276,7 +276,7 @@ fn get_dest_from_to(to: &str) -> Result> { fn get_sql_from_query(query: &str) -> Result { let sql = if query.starts_with("prql ") { - compile(query, None).map_err(|e| anyhow!(e))? + compile(query)? } else { query.to_string() }; @@ -288,14 +288,14 @@ fn standardise_sources(from: &FromType) -> Result { let supported_file_types: HashSet<&str> = HashSet::from(SUPPORTED_FILE_TYPES); // let mut sources : Vec<(String, String)> = Vec::<(String, String)>::new(); let mut sources: SourcesType = SourcesType::new(); - for from_str in from.iter() { - let mut from_parts: Vec = from_str.split("=").map(|s| s.to_string()).collect(); - if from_parts.len() == 1 { - let filepath = Utf8Path::new(&from_parts[0]); - let file_ext = filepath + for fromstr in from.iter() { + let mut fromparts: Vec = fromstr.split("=").map(|s| s.to_string()).collect(); + if fromparts.len() == 1 { + let filepath = Utf8Path::new(&fromparts[0]); + let fileext = filepath .extension() .ok_or(anyhow!("No extension in: {filepath}"))?; - if supported_file_types.contains(&file_ext) { + if supported_file_types.contains(&fileext) { // Dealing with a file let last_component = filepath .components() @@ -306,16 +306,16 @@ fn standardise_sources(from: &FromType) -> Result { .split(".") .next() .ok_or(anyhow!("No filename found in: {last_component}"))?; - let table_name = filename.replace(" ", "_"); - from_parts = vec![table_name, from_parts[0].clone()]; + let tablename = filename.replace(" ", "_"); + fromparts = vec![tablename, fromparts[0].clone()]; } else { // Dealing with a possible tablename with schema prefix - let table_parts: Vec<&str> = from_parts[0].split(" ").collect(); - let table_name = table_parts.last().ok_or(anyhow!("No last tablepart"))?; - from_parts = vec![table_name.to_string(), from_parts[0].clone()]; + let tableparts: Vec<&str> = fromparts[0].split(" ").collect(); + let tablename = tableparts.last().ok_or(anyhow!("No last tablepart"))?; + fromparts = vec![tablename.to_string(), fromparts[0].clone()]; } } - sources.push((from_parts[0].clone(), from_parts[1].clone())); + sources.push((fromparts[0].clone(), fromparts[1].clone())); } debug!("sources={sources:?}"); Ok(sources)