Skip to content
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

Add type to ast::Lit::EmbeddedDocLit #525

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, _) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the type argument be used in the following line rather than the hard-coded Ion?

Copy link
Contributor Author

@jpschorr jpschorr Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually, but there's not enough in place to do so meaningfully in the PR. This will be the extension mechanism for boxed documents. For now, only Ion is supported.

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
Loading