You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/08/14 17:13:06 UTC
[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #7276: Enable creating and inserting to empty external tables via SQL
alamb commented on code in PR #7276:
URL: https://github.com/apache/arrow-datafusion/pull/7276#discussion_r1293749583
##########
datafusion/core/src/datasource/listing/table.rs:
##########
@@ -2096,4 +2230,64 @@ mod tests {
// Return Ok if the function
Ok(())
}
+
+ /// tests insert into with end to end sql
+ /// create external table + insert into statements
+ async fn helper_test_insert_into_sql(
+ file_type: &str,
+ // TODO test with create statement options such as compression
+ _file_compression_type: FileCompressionType,
+ external_table_options: &str,
+ session_config_map: Option<HashMap<String, String>>,
+ ) -> Result<()> {
+ // Create the initial context
+ let session_ctx = match session_config_map {
+ Some(cfg) => {
+ let config = SessionConfig::from_string_hash_map(cfg)?;
+ SessionContext::with_config(config)
+ }
+ None => SessionContext::new(),
+ };
+
+ // create table
+ let tmp_dir = TempDir::new()?;
+ let tmp_path = tmp_dir.into_path();
+ let str_path = tmp_path.to_str().expect("Temp path should convert to &str");
+ session_ctx
+ .sql(&format!(
+ "create external table foo(a varchar, b varchar, c int) \
+ stored as {file_type} \
+ location '{str_path}' \
+ {external_table_options}"
+ ))
+ .await?
+ .collect()
+ .await?;
+
+ // insert data
+ session_ctx.sql("insert into foo values ('foo', 'bar', 1),('foo', 'bar', 2), ('foo', 'bar', 3)")
+ .await?
+ .collect()
+ .await?;
+
+ // check count
+ let batches = session_ctx
+ .sql("select * from foo")
+ .await?
+ .collect()
+ .await?;
+
+ let expected = vec![
Review Comment:
this is very cool.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org