Skip to content

Commit

Permalink
Merge 4de6533 into d07a7e1
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr authored Dec 5, 2024
2 parents d07a7e1 + 4de6533 commit a310ffa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion extension/partiql-extension-visualize/src/ast_to_dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn lit_to_str(ast: &ast::Lit) -> String {
Lit::FloatLit(l) => l.to_string(),
Lit::DoubleLit(l) => l.to_string(),
Lit::BoolLit(l) => (if *l { "TRUE" } else { "FALSE" }).to_string(),
Lit::EmbeddedDocLit(l) => format!("`{}`", l),
Lit::EmbeddedDocLit(l, typ) => format!("`{}`::{}", l, type_to_str(typ)),
Lit::CharStringLit(l) => format!("'{}'", l),
Lit::NationalCharStringLit(l) => format!("'{}'", l),
Lit::BitStringLit(l) => format!("b'{}'", l),
Expand Down
2 changes: 1 addition & 1 deletion partiql-ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pub enum Lit {
#[visit(skip)]
BoolLit(bool),
#[visit(skip)]
EmbeddedDocLit(String),
EmbeddedDocLit(String, Type),
#[visit(skip)]
CharStringLit(String),
#[visit(skip)]
Expand Down
31 changes: 27 additions & 4 deletions partiql-ast/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl PrettyDoc for Lit {
Lit::FloatLit(inner) => arena.text(inner.to_string()),
Lit::DoubleLit(inner) => arena.text(inner.to_string()),
Lit::BoolLit(inner) => arena.text(inner.to_string()),
Lit::EmbeddedDocLit(inner) => inner.pretty_doc(arena), // TODO better pretty for embedded doc: https://github.com/partiql/partiql-lang-rust/issues/508
Lit::EmbeddedDocLit(inner, _typ) => inner.pretty_doc(arena), // TODO better pretty for embedded doc: https://github.com/partiql/partiql-lang-rust/issues/508
Lit::CharStringLit(inner) => inner.pretty_doc(arena),
Lit::NationalCharStringLit(inner) => inner.pretty_doc(arena),
Lit::BitStringLit(inner) => inner.pretty_doc(arena),
Expand All @@ -420,9 +420,32 @@ impl PrettyDoc for Type {
{
match self {
Type::CustomType(cty) => cty.pretty_doc(arena),
_ => {
todo!("Non-custom type type")
}
Type::NullType => arena.text("NULL"),
Type::BooleanType => arena.text("BOOL"),
Type::Integer2Type => arena.text("INT2"),
Type::Integer4Type => arena.text("INT4"),
Type::Integer8Type => arena.text("INT8"),
Type::DecimalType => arena.text("DECIMAL"),
Type::NumericType => arena.text("NUMERIC"),
Type::RealType => arena.text("REAL"),
Type::DoublePrecisionType => arena.text("DOUBLE PRECISION"),
Type::TimestampType => arena.text("TIMESTAMP"),
Type::CharacterType => arena.text("CHAR"),
Type::CharacterVaryingType => arena.text("VARCHAR"),
Type::MissingType => arena.text("MISSING"),
Type::StringType => arena.text("STRING"),
Type::SymbolType => arena.text("SYMBOL"),
Type::BlobType => arena.text("BLOB"),
Type::ClobType => arena.text("CLOB"),
Type::DateType => arena.text("DATE"),
Type::TimeType => arena.text("TIME"),
Type::ZonedTimestampType => arena.text("TIMESTAMPTZ"),
Type::StructType => arena.text("STRUCT"),
Type::TupleType => arena.text("TUPLE"),
Type::ListType => arena.text("LIST"),
Type::SexpType => arena.text("SEXP"),
Type::BagType => arena.text("BAG"),
Type::AnyType => arena.text("ANY"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion partiql-logical-planner/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ fn lit_to_lit(lit: &Lit) -> Result<logical::Lit, AstTransformError> {
Lit::FloatLit(f) => logical::Lit::Double(OrderedFloat::from(*f as f64)),
Lit::DoubleLit(f) => logical::Lit::Double(OrderedFloat::from(*f)),
Lit::BoolLit(b) => logical::Lit::Bool(*b),
Lit::EmbeddedDocLit(s) => {
Lit::EmbeddedDocLit(s, _) => {
logical::Lit::BoxDocument(s.clone().into_bytes(), "Ion".to_string())
}
Lit::CharStringLit(s) => logical::Lit::String(s.clone()),
Expand Down
10 changes: 9 additions & 1 deletion partiql-parser/src/parse/partiql.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,15 @@ LiteralNumber: ast::Lit = {

#[inline]
LiteralEmbeddedDoc: ast::Lit = {
<ion:"EmbeddedDoc"> => ast::Lit::EmbeddedDocLit(ion.to_owned()),
<ion:"EmbeddedDoc"> => {
let ion_typ = ast::Type::CustomType(ast::CustomType {
parts: vec![ast::CustomTypePart::Name(ast::SymbolPrimitive {
value: "Ion".to_string(),
case: ast::CaseSensitivity::CaseInsensitive,
})],
});
ast::Lit::EmbeddedDocLit(ion.to_owned(), ion_typ)
}
}


Expand Down

0 comments on commit a310ffa

Please sign in to comment.