Skip to content
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
18 changes: 12 additions & 6 deletions PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,6 @@ name: nullable varchar(255)
The name of the user in the system.
```

- https://r.ena.to/blog/optimizing-postgres-table-layout-for-maximum-efficiency/

rust analyzer gives:

```
Expand All @@ -714,13 +712,21 @@ Error { pub(crate) msg: String, }
size = 24 (0x18), align = 0x8, needs Drop
```

does alignment make sense to have with postgres?
other fields?

- alignment

- https://r.ena.to/blog/optimizing-postgres-table-layout-for-maximum-efficiency/

- common values and distribution

- https://observablehq.com/documentation/cells/data-table#data-table-cell

maybe have common values and distribution somehow?
- index size on hover

show index size on hover too?
- https://www.peterbe.com/plog/index-size-postgresql

- https://www.peterbe.com/plog/index-size-postgresql
- data staleness -- if you have a daily batch job to calculate data, we could expose the staleness date

#### Table

Expand Down
5 changes: 4 additions & 1 deletion crates/squawk_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,7 @@ fn arg_expr(p: &mut Parser<'_>) -> Option<CompletedMarker> {
p.eat(VARIADIC_KW);
let r = Restrictions {
order_by_allowed: true,
as_allowed: true,
..Restrictions::default()
};
expr_bp(p, 1, &r)
Expand Down Expand Up @@ -2300,6 +2301,7 @@ fn current_op(p: &Parser<'_>, r: &Restrictions) -> (u8, SyntaxKind, Associativit
PERCENT if p.next_not_joined_op(0) => (9, PERCENT, Left), // symbol
// and
AND_KW if !r.and_disabled => (2, AND_KW, Left),
AS_KW if r.as_allowed => (7, AS_KW, Left),
// /
SLASH if p.next_not_joined_op(0) => (9, SLASH, Left), // symbol
// *
Expand All @@ -2326,6 +2328,7 @@ const OVERLAPPING_TOKENS: TokenSet = TokenSet::new(&[OR_KW, AND_KW, IS_KW, COLLA
#[derive(Default)]
struct Restrictions {
order_by_allowed: bool,
as_allowed: bool,
in_disabled: bool,
is_disabled: bool,
not_disabled: bool,
Expand Down Expand Up @@ -2383,7 +2386,7 @@ fn expr_bp(p: &mut Parser<'_>, bp: u8, r: &Restrictions) -> Option<CompletedMark
let _ = expr_bp(p, op_bp, r);
lhs = m.complete(
p,
if op == SyntaxKind::COLON_COLON {
if matches!(op, COLON_COLON | AS_KW) {
CAST_EXPR
} else if matches!(op, FAT_ARROW | COLON_EQ) {
NAMED_ARG
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/squawk_syntax/src/test.rs
input_file: crates/squawk_syntax/test_data/validation/call_expr.sql
---
SOURCE_FILE@0..97
COMMENT@0..69 "-- Trino/Snowflake/Da ..."
WHITESPACE@69..70 "\n"
SELECT@70..95
SELECT_CLAUSE@70..95
SELECT_KW@70..76 "select"
WHITESPACE@76..77 " "
TARGET_LIST@77..95
TARGET@77..95
CALL_EXPR@77..95
NAME_REF@77..85
IDENT@77..85 "try_cast"
ARG_LIST@85..95
L_PAREN@85..86 "("
CAST_EXPR@86..94
NAME_REF@86..87
IDENT@86..87 "x"
WHITESPACE@87..88 " "
AS_KW@88..90 "as"
WHITESPACE@90..91 " "
NAME_REF@91..94
INT_KW@91..94 "int"
R_PAREN@94..95 ")"
SEMICOLON@95..96 ";"
WHITESPACE@96..97 "\n"

ERROR@86:94 "Invalid cast. Use `cast`, `treat`, or `::` instead."
15 changes: 15 additions & 0 deletions crates/squawk_syntax/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
ast::PrefixExpr(it) => validate_prefix_expr(it, errors),
ast::ArrayExpr(it) => validate_array_expr(it, errors),
ast::DropAggregate(it) => validate_drop_aggregate(it, errors),
ast::CallExpr(it) => validate_call_expr(it, errors),
ast::JoinExpr(it) => validate_join_expr(it, errors),
ast::Literal(it) => validate_literal(it, errors),
ast::NonStandardParam(it) => validate_non_standard_param(it, errors),
Expand All @@ -27,6 +28,20 @@ pub(crate) fn validate(root: &SyntaxNode, errors: &mut Vec<SyntaxError>) {
}
}

fn validate_call_expr(it: ast::CallExpr, acc: &mut Vec<SyntaxError>) {
let Some(arg_list) = it.arg_list() else {
return;
};
for arg in arg_list.args() {
if let ast::Expr::CastExpr(cast_expr) = &arg {
acc.push(SyntaxError::new(
"Invalid cast. Use `cast`, `treat`, or `::` instead.",
cast_expr.syntax().text_range(),
));
}
}
}

fn validate_create_table(it: ast::CreateTable, acc: &mut Vec<SyntaxError>) {
let Some(arg_list) = it.table_arg_list() else {
return;
Expand Down
2 changes: 2 additions & 0 deletions crates/squawk_syntax/test_data/validation/call_expr.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Trino/Snowflake/Databricks extension that Postgres doesn't support
select try_cast(x as int);
Loading