-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use thrift to generate hms client stub code
- Loading branch information
1 parent
9ee5ed4
commit a1cf11e
Showing
12 changed files
with
153 additions
and
74,839 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
[package] | ||
name = "common-hive-meta-store" | ||
version = "0.1.0" | ||
authors = ["Databend Authors <[email protected]>"] | ||
license = "Apache-2.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[lib] | ||
doctest = false | ||
test = false | ||
|
||
[dependencies] # In alphabetical order | ||
# Workspace dependencies | ||
common-base = { path = "../base" } | ||
common-exception = { path = "../exception" } | ||
common-tracing = { path = "../tracing" } | ||
|
||
# Github dependencies | ||
|
||
# Crates.io dependencies | ||
thrift = "0.15" | ||
|
||
[build-dependencies] |
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 @@ | ||
// Copyright 2021 Datafuse Labs. | ||
// | ||
// Licensed 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; | ||
use std::fs::File; | ||
use std::io::BufRead; | ||
use std::io::BufReader; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::process::Command; | ||
|
||
#[allow(clippy::expect_fun_call)] | ||
fn main() { | ||
let out_dir = env::var_os("OUT_DIR").unwrap(); | ||
let dest_path = Path::new(&out_dir); | ||
|
||
// thrift -out my_rust_program/src --gen rs -r Tutorial.thrift | ||
Command::new("thrift") | ||
.args(&[ | ||
"-out", | ||
&dest_path.as_os_str().to_string_lossy(), | ||
"-gen", | ||
"rs", | ||
"-r", | ||
"src/idl/hms.thrift", | ||
]) | ||
.status() | ||
.unwrap(); | ||
|
||
// unfortunately, the code that thrift generated contains attributes attributes | ||
// which will prevent us from using `include!` macro to embed the codes. | ||
// | ||
// If we `include!` the code generated directly, rustc will reports errors like this: | ||
// | ||
// "error: an inner attribute is not permitted following an outer attribute" | ||
// | ||
// see also: | ||
// 1. https://github.com/rust-lang/rfcs/issues/752 | ||
// 2. https://github.com/google/flatbuffers/pull/6410 | ||
// | ||
// thus, we have to "patch" the code that thrift generated. | ||
|
||
let input_file_path = dest_path.join("hms.rs"); | ||
let output_file_path = dest_path.join("hms_patched.rs"); | ||
let input = BufReader::new( | ||
File::open(&input_file_path) | ||
.expect(format!("open generated file failure: {:?}", input_file_path).as_str()), | ||
); | ||
let mut output = File::create(output_file_path).expect("create output patch file failure"); | ||
for line in input.lines() { | ||
let line = line.expect("readline failure"); | ||
if !line.starts_with("#![") { | ||
std::writeln!(output, "{}", line).expect("write line to patched file failure"); | ||
} | ||
} | ||
|
||
println!("cargo:rerun-if-changed=build.rs"); | ||
} |
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,15 @@ | ||
// Copyright 2021 Datafuse Labs. | ||
// | ||
// Licensed 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. | ||
|
||
include!(concat!(env!("OUT_DIR"), "/hms_patched.rs")); |
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 @@ | ||
// Copyright 2021 Datafuse Labs. | ||
// | ||
// Licensed 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. | ||
|
||
#![allow(clippy::all)] | ||
#![allow(dead_code)] | ||
#![allow(unreachable_patterns)] | ||
#![allow(unused_imports)] | ||
#![allow(unused_variables)] | ||
#![allow(unused_extern_crates)] | ||
#![allow(deprecated)] | ||
#![allow(clippy::too_many_arguments, clippy::type_complexity, clippy::vec_box)] | ||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
mod hive_meta_store; | ||
|
||
pub use hive_meta_store::TThriftHiveMetastoreSyncClient; | ||
pub use hive_meta_store::ThriftHiveMetastoreSyncClient; | ||
pub use hive_meta_store::*; | ||
pub use thrift; |
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
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
Oops, something went wrong.