-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(rust/driver/snowflake): add adbc_snowflake
crate with Go driver wrapper
#2207
Draft
mbrobbel
wants to merge
21
commits into
apache:main
Choose a base branch
from
mbrobbel:rust/snowflake
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,943
−112
Draft
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7dd0c67
feat(rust/driver/snowflake): add `adbc_snowflake` crate with Go drive…
mbrobbel 0ed54ab
Rename `rust/drivers` to `rust/driver`
mbrobbel ea19114
Add required permissions for `native-unix` workflow
mbrobbel 691785a
Also add `contents: read` to permissions for `native-unix` workflow
mbrobbel a213419
Merge branch 'main' into rust/snowflake
mbrobbel 88d8809
Merge branch 'main' into rust/snowflake
mbrobbel 23b995f
Merge branch 'main' into rust/snowflake
mbrobbel b541e07
Also move `datafusion` to `driver`
mbrobbel 277bbc9
Fix unused warning
mbrobbel 4e6d9ce
Add configuration builders
mbrobbel e6f3638
Add missing license headers
mbrobbel b6e7cd1
Fix clippy warning
mbrobbel c686f2e
Add `bundled` and `linked` features to control linking
mbrobbel 032cb92
Use testing database in CI
mbrobbel 25a86c9
Merge branch 'main' into rust/snowflake
mbrobbel 80898f1
Add go lib dir to search path
mbrobbel cf54213
Disable integration tests for now
mbrobbel 7b3ed83
Ignore load dynamic driver test when `linked` feature is not set
mbrobbel af70f82
Set `ADBC_SNOWFLAKE_GO_LIB_DIR` for all steps
mbrobbel 041f72d
Add `adbc_snowflake` to release script
mbrobbel 0229b41
Add some get info methods and tests
mbrobbel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "adbc_snowflake" | ||
description = "Snowflake Arrow Database Connectivity (ADBC) driver" | ||
version.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
adbc_core = { path = "../../core", features = ["driver_manager"] } | ||
arrow-array.workspace = true | ||
arrow-schema.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!--- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# Snowflake driver for Arrow Database Connectivity (ADBC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::{env, error::Error, path::PathBuf, process::Command}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); | ||
let go_dir = manifest_dir.ancestors().nth(3).unwrap().join("go"); | ||
let go_pkg = go_dir.join("adbc/pkg/snowflake"); | ||
|
||
let out_dir = PathBuf::from(env::var("OUT_DIR")?); | ||
let archive = out_dir.join("libsnowflake.a"); | ||
|
||
// Build the Go driver | ||
let status = Command::new("go") | ||
.current_dir(go_pkg.as_path()) | ||
.arg("build") | ||
.arg("-tags") | ||
.arg("driverlib") | ||
.arg("-buildmode=c-archive") | ||
.arg("-o") | ||
.arg(&archive) | ||
.arg(".") | ||
.status()?; | ||
assert!(status.success(), "Go build failed"); | ||
|
||
// Rebuild when the Go pkg changes. | ||
println!("cargo:rerun-if-changed={}", go_pkg.display()); | ||
|
||
// Link the driver statically. | ||
println!("cargo:rustc-link-search=native={}", out_dir.display()); | ||
println!("cargo:rustc-link-lib=static=snowflake"); | ||
|
||
// Link other dependencies. | ||
println!("cargo:rustc-link-lib=resolv"); | ||
#[cfg(target_os = "macos")] | ||
{ | ||
println!("cargo:rustc-link-lib=framework=CoreFoundation"); | ||
println!("cargo:rustc-link-lib=framework=Security"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::collections::HashSet; | ||
|
||
use adbc_core::{ | ||
driver_manager::ManagedConnection, | ||
error::Result, | ||
options::{InfoCode, OptionConnection, OptionValue}, | ||
Connection, Optionable, | ||
}; | ||
use arrow_array::RecordBatchReader; | ||
use arrow_schema::Schema; | ||
|
||
use crate::SnowflakeStatement; | ||
|
||
/// Snowflake ADBC Connection. | ||
pub struct SnowflakeConnection(pub(crate) ManagedConnection); | ||
|
||
impl Optionable for SnowflakeConnection { | ||
type Option = OptionConnection; | ||
|
||
fn set_option(&mut self, key: Self::Option, value: OptionValue) -> Result<()> { | ||
self.0.set_option(key, value) | ||
} | ||
|
||
fn get_option_string(&self, key: Self::Option) -> Result<String> { | ||
self.0.get_option_string(key) | ||
} | ||
|
||
fn get_option_bytes(&self, key: Self::Option) -> Result<Vec<u8>> { | ||
self.0.get_option_bytes(key) | ||
} | ||
|
||
fn get_option_int(&self, key: Self::Option) -> Result<i64> { | ||
self.0.get_option_int(key) | ||
} | ||
|
||
fn get_option_double(&self, key: Self::Option) -> Result<f64> { | ||
self.0.get_option_double(key) | ||
} | ||
} | ||
|
||
impl Connection for SnowflakeConnection { | ||
type StatementType = SnowflakeStatement; | ||
|
||
fn new_statement(&mut self) -> Result<Self::StatementType> { | ||
self.0.new_statement().map(SnowflakeStatement) | ||
} | ||
|
||
fn cancel(&mut self) -> Result<()> { | ||
self.0.cancel() | ||
} | ||
|
||
fn get_info(&self, codes: Option<HashSet<InfoCode>>) -> Result<impl RecordBatchReader + Send> { | ||
self.0.get_info(codes) | ||
} | ||
|
||
fn get_objects( | ||
&self, | ||
depth: adbc_core::options::ObjectDepth, | ||
catalog: Option<&str>, | ||
db_schema: Option<&str>, | ||
table_name: Option<&str>, | ||
table_type: Option<Vec<&str>>, | ||
column_name: Option<&str>, | ||
) -> Result<impl RecordBatchReader + Send> { | ||
self.0.get_objects( | ||
depth, | ||
catalog, | ||
db_schema, | ||
table_name, | ||
table_type, | ||
column_name, | ||
) | ||
} | ||
|
||
fn get_table_schema( | ||
&self, | ||
catalog: Option<&str>, | ||
db_schema: Option<&str>, | ||
table_name: &str, | ||
) -> Result<Schema> { | ||
self.0.get_table_schema(catalog, db_schema, table_name) | ||
} | ||
|
||
fn get_table_types(&self) -> Result<impl RecordBatchReader + Send> { | ||
self.0.get_table_types() | ||
} | ||
|
||
fn get_statistic_names(&self) -> Result<impl RecordBatchReader + Send> { | ||
self.0.get_statistic_names() | ||
} | ||
|
||
fn get_statistics( | ||
&self, | ||
catalog: Option<&str>, | ||
db_schema: Option<&str>, | ||
table_name: Option<&str>, | ||
approximate: bool, | ||
) -> Result<impl RecordBatchReader + Send> { | ||
self.0 | ||
.get_statistics(catalog, db_schema, table_name, approximate) | ||
} | ||
|
||
fn commit(&mut self) -> Result<()> { | ||
self.0.commit() | ||
} | ||
|
||
fn rollback(&mut self) -> Result<()> { | ||
self.0.rollback() | ||
} | ||
|
||
fn read_partition(&self, partition: impl AsRef<[u8]>) -> Result<impl RecordBatchReader + Send> { | ||
self.0.read_partition(partition) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use adbc_core::{ | ||
driver_manager::ManagedDatabase, | ||
error::Result, | ||
options::{OptionConnection, OptionDatabase, OptionValue}, | ||
Database, Optionable, | ||
}; | ||
|
||
use crate::SnowflakeConnection; | ||
|
||
/// Snowflake ADBC Database. | ||
pub struct SnowflakeDatabase(pub(crate) ManagedDatabase); | ||
|
||
impl Optionable for SnowflakeDatabase { | ||
type Option = OptionDatabase; | ||
|
||
fn set_option(&mut self, key: Self::Option, value: OptionValue) -> Result<()> { | ||
self.0.set_option(key, value) | ||
} | ||
|
||
fn get_option_string(&self, key: Self::Option) -> Result<String> { | ||
self.0.get_option_string(key) | ||
} | ||
|
||
fn get_option_bytes(&self, key: Self::Option) -> Result<Vec<u8>> { | ||
self.0.get_option_bytes(key) | ||
} | ||
|
||
fn get_option_int(&self, key: Self::Option) -> Result<i64> { | ||
self.0.get_option_int(key) | ||
} | ||
|
||
fn get_option_double(&self, key: Self::Option) -> Result<f64> { | ||
self.0.get_option_double(key) | ||
} | ||
} | ||
|
||
impl Database for SnowflakeDatabase { | ||
type ConnectionType = SnowflakeConnection; | ||
|
||
fn new_connection(&mut self) -> Result<Self::ConnectionType> { | ||
self.0.new_connection().map(SnowflakeConnection) | ||
} | ||
|
||
fn new_connection_with_opts( | ||
&mut self, | ||
opts: impl IntoIterator<Item = (OptionConnection, OptionValue)>, | ||
) -> Result<Self::ConnectionType> { | ||
self.0 | ||
.new_connection_with_opts(opts) | ||
.map(SnowflakeConnection) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with Rust, but can't these just be inherited somehow from a base type instead of having to implement them here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should be using traits for this. Discussed before here: #1725 (comment).
I'll try to put up a PR to change these option structs to traits following the proposal in #1725 (comment).