-
Notifications
You must be signed in to change notification settings - Fork 592
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
refactor(source): minor refactors on source parser #17184
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0680e9
refactor: move json schema to codec crate
xxchan 9fe97c4
remove dead code
xxchan 52874e8
cleanup avro
xxchan d1d66fa
revert toml fmt change
xxchan 86b47d1
Revert "remove dead code"
xxchan d4ae5fc
B happy
xxchan c28b986
fix lock
xxchan 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
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
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,35 @@ | ||
// Copyright 2024 RisingWave 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 anyhow::Context; | ||
use risingwave_pb::plan_common::ColumnDesc; | ||
|
||
use super::avro::{avro_schema_to_column_descs, MapHandling}; | ||
|
||
impl crate::JsonSchema { | ||
/// FIXME: when the JSON schema is invalid, it will panic. | ||
/// | ||
/// ## Notes on type conversion | ||
/// Map will be used when an object doesn't have `properties` but has `additionalProperties`. | ||
/// When an object has `properties` and `additionalProperties`, the latter will be ignored. | ||
/// <https://github.com/mozilla/jsonschema-transpiler/blob/fb715c7147ebd52427e0aea09b2bba2d539850b1/src/jsonschema.rs#L228-L280> | ||
/// | ||
/// TODO: examine other stuff like `oneOf`, `patternProperties`, etc. | ||
pub fn json_schema_to_columns(&self) -> anyhow::Result<Vec<ColumnDesc>> { | ||
let avro_schema = jst::convert_avro(&self.0, jst::Context::default()).to_string(); | ||
let schema = | ||
apache_avro::Schema::parse_str(&avro_schema).context("failed to parse avro schema")?; | ||
avro_schema_to_column_descs(&schema, Some(MapHandling::Jsonb)).map_err(Into::into) | ||
} | ||
} |
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
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
This file was deleted.
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 |
---|---|---|
|
@@ -24,15 +24,12 @@ | |
use std::collections::BTreeMap; | ||
|
||
use anyhow::Context as _; | ||
use apache_avro::Schema; | ||
use jst::{convert_avro, Context}; | ||
use risingwave_connector_codec::decoder::avro::MapHandling; | ||
use risingwave_connector_codec::JsonSchema; | ||
use risingwave_pb::plan_common::ColumnDesc; | ||
|
||
use super::util::{bytes_from_url, get_kafka_topic}; | ||
use super::{JsonProperties, SchemaRegistryAuth}; | ||
use crate::error::ConnectorResult; | ||
use crate::parser::avro::util::avro_schema_to_column_descs; | ||
use crate::parser::unified::json::{JsonAccess, JsonParseOptions}; | ||
use crate::parser::unified::AccessImpl; | ||
use crate::parser::AccessBuilder; | ||
|
@@ -93,27 +90,13 @@ pub async fn fetch_json_schema_and_map_to_columns( | |
let schema = client | ||
.get_schema_by_subject(&format!("{}-value", topic)) | ||
.await?; | ||
serde_json::from_str(&schema.content)? | ||
JsonSchema::parse_str(&schema.content)? | ||
} else { | ||
let url = url.first().unwrap(); | ||
let bytes = bytes_from_url(url, None).await?; | ||
serde_json::from_slice(&bytes)? | ||
JsonSchema::parse_bytes(&bytes)? | ||
}; | ||
json_schema_to_columns(&json_schema) | ||
} | ||
|
||
/// FIXME: when the JSON schema is invalid, it will panic. | ||
/// | ||
/// ## Notes on type conversion | ||
/// Map will be used when an object doesn't have `properties` but has `additionalProperties`. | ||
/// When an object has `properties` and `additionalProperties`, the latter will be ignored. | ||
/// <https://github.com/mozilla/jsonschema-transpiler/blob/fb715c7147ebd52427e0aea09b2bba2d539850b1/src/jsonschema.rs#L228-L280> | ||
/// | ||
/// TODO: examine other stuff like `oneOf`, `patternProperties`, etc. | ||
fn json_schema_to_columns(json_schema: &serde_json::Value) -> ConnectorResult<Vec<ColumnDesc>> { | ||
let avro_schema = convert_avro(json_schema, Context::default()).to_string(); | ||
let schema = Schema::parse_str(&avro_schema).context("failed to parse avro schema")?; | ||
avro_schema_to_column_descs(&schema, Some(MapHandling::Jsonb)).map_err(Into::into) | ||
json_schema.json_schema_to_columns().map_err(Into::into) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
} | ||
|
||
#[cfg(test)] | ||
|
This file was deleted.
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
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.
This is changed because I found
cargo check -p risingwave_connector
compile failed.