MCPcopy Create free account
hub / github.com/apache/datafusion / process_query_directive

Method process_query_directive

benchmarks/src/sql_benchmark.rs:785–860  ·  view source on GitHub ↗
(
        bench: &mut SqlBenchmark,
        reader: &mut BenchmarkFileReader,
        line: &mut String,
        splits: &[&str],
    )

Source from the content-addressed store, hash-verified

783 }
784
785 fn process_query_directive(
786 bench: &mut SqlBenchmark,
787 reader: &mut BenchmarkFileReader,
788 line: &mut String,
789 splits: &[&str],
790 ) -> Result<()> {
791 let directive = QueryDirective::parse(splits[0]).ok_or_else(|| {
792 exec_datafusion_err!("Invalid query directive: {}", splits[0])
793 })?;
794
795 if directive == QueryDirective::Run && bench.queries.contains_key(&directive) {
796 return Err(exec_datafusion_err!(
797 "Multiple calls to run in the same benchmark file"
798 ));
799 }
800
801 line.clear();
802
803 // Read the query body until a blank line or EOF.
804 let mut query = String::new();
805 let mut reader_result = reader.read_line(line);
806
807 loop {
808 match reader_result {
809 Some(Ok(_)) => {
810 if is_comment_line(line) {
811 // comment, ignore
812 } else if is_blank_line(line) {
813 break;
814 } else {
815 query.push_str(line);
816 query.push('\n');
817 }
818 }
819 Some(Err(e)) => return Err(e),
820 None => break,
821 }
822
823 // Clear the line buffer for the next iteration.
824 line.clear();
825 reader_result = reader.read_line(line);
826 }
827
828 // Optional file parameter.
829 if splits.len() > 1 && !splits[1].is_empty() {
830 if !query.trim().is_empty() {
831 return Err(exec_datafusion_err!(
832 "{}",
833 reader.format_exception(&format!(
834 "{} directive must use either a query file or inline SQL, not both",
835 directive.as_str()
836 ))
837 ));
838 }
839
840 debug!("Processing {} file: {}", splits[0], splits[1]);
841
842 let query_file = fs::read_to_string(splits[1]).map_err(|e| {

Callers

nothing calls this directly

Calls 13

newFunction · 0.85
is_comment_lineFunction · 0.85
is_blank_lineFunction · 0.85
split_query_statementsFunction · 0.85
read_lineMethod · 0.80
trimMethod · 0.80
process_queryMethod · 0.80
contains_keyMethod · 0.45
clearMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected