fix(json2): encode deeply nested values as jsonb (#8612)

* fix(json2): encode deeply nested values as jsonb

Signed-off-by: fys <fengys1996@gmail.com>

* add more sqlness

Signed-off-by: fys <fengys1996@gmail.com>

* some changes

Signed-off-by: fys <fengys1996@gmail.com>

* fix(json2): limit type hint path depth

Signed-off-by: fys <fengys1996@gmail.com>

---------

Signed-off-by: fys <fengys1996@gmail.com>
This commit is contained in:
fys
2026-07-23 10:29:31 +00:00
committed by GitHub
parent bfd7abb0b8
commit 837b701e68
9 changed files with 534 additions and 6 deletions
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use datatypes::json::JSON2_MAX_STRUCTURED_DEPTH;
use snafu::{ResultExt, ensure};
use sqlparser::ast::{DataType, ExactNumberInfo, Expr, ObjectName, UnaryOperator};
use sqlparser::dialect::keywords::Keyword;
@@ -76,6 +77,14 @@ fn parse_json2_type_hints(parser: &mut Parser<'_>) -> Result<Vec<JsonTypeHint>>
fn parse_json2_type_hint(parser: &mut Parser<'_>) -> Result<JsonTypeHint> {
let path = parse_json2_path(parser)?;
ensure!(
path.len() <= JSON2_MAX_STRUCTURED_DEPTH,
InvalidSqlSnafu {
msg: format!(
"JSON2 type hint path cannot exceed {JSON2_MAX_STRUCTURED_DEPTH} segments"
),
}
);
let data_type = parser.parse_data_type().context(SyntaxSnafu)?;
let data_type = normalize_json2_type_hint_type(data_type)?;