mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-16 06:34:20 +01:00
remove pattern matching over Name::Quoted
This commit is contained in:
@@ -448,9 +448,7 @@ impl IncrementalView {
|
||||
// Store the alias mapping if there is an alias
|
||||
if let Some(alias_enum) = alias {
|
||||
let alias_name = match alias_enum {
|
||||
ast::As::As(name) | ast::As::Elided(name) => match name {
|
||||
ast::Name::Ident(s) | ast::Name::Quoted(s) => s,
|
||||
},
|
||||
ast::As::As(name) | ast::As::Elided(name) => name.as_str(),
|
||||
};
|
||||
aliases.insert(alias_name.to_string(), table_name.to_string());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ use std::sync::Mutex;
|
||||
use tracing::trace;
|
||||
use turso_parser::ast::{self, ColumnDefinition, Expr, Literal, SortOrder, TableOptions};
|
||||
use turso_parser::{
|
||||
ast::{Cmd, CreateTableBody, Name, ResultColumn, Stmt},
|
||||
ast::{Cmd, CreateTableBody, ResultColumn, Stmt},
|
||||
parser::Parser,
|
||||
};
|
||||
|
||||
@@ -1927,7 +1927,7 @@ impl Index {
|
||||
match e {
|
||||
Expr::Literal(_) | Expr::RowId { .. } => {}
|
||||
// Unqualified identifier: must be a column of the target table or ROWID
|
||||
Expr::Id(Name::Ident(n)) | Expr::Id(Name::Quoted(n)) => {
|
||||
Expr::Id(n) => {
|
||||
let n = n.as_str();
|
||||
if !ROWID_STRS.iter().any(|s| s.eq_ignore_ascii_case(n)) && !has_col(n) {
|
||||
ok = false;
|
||||
|
||||
@@ -1844,7 +1844,7 @@ fn rewrite_where_for_update_registers(
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Id(ast::Name::Ident(name)) | Expr::Id(ast::Name::Quoted(name)) => {
|
||||
Expr::Id(name) => {
|
||||
let normalized = normalize_ident(name.as_str());
|
||||
if ROWID_STRS
|
||||
.iter()
|
||||
|
||||
@@ -3302,10 +3302,10 @@ pub fn bind_and_rewrite_expr<'a>(
|
||||
top_level_expr,
|
||||
&mut |expr: &mut ast::Expr| -> Result<WalkControl> {
|
||||
match expr {
|
||||
ast::Expr::Id(ast::Name::Ident(n)) if n.eq_ignore_ascii_case("true") => {
|
||||
ast::Expr::Id(n) if n.as_str().eq_ignore_ascii_case("true") => {
|
||||
*expr = ast::Expr::Literal(ast::Literal::Numeric("1".to_string()));
|
||||
}
|
||||
ast::Expr::Id(ast::Name::Ident(n)) if n.eq_ignore_ascii_case("false") => {
|
||||
ast::Expr::Id(n) if n.as_str().eq_ignore_ascii_case("false") => {
|
||||
*expr = ast::Expr::Literal(ast::Literal::Numeric("0".to_string()));
|
||||
}
|
||||
// Rewrite anonymous variables in encounter order.
|
||||
|
||||
@@ -21,7 +21,7 @@ use crate::{
|
||||
insn::{IdxInsertFlags, Insn, RegisterOrLiteral},
|
||||
},
|
||||
};
|
||||
use turso_parser::ast::{self, Expr, SortOrder, SortedColumn};
|
||||
use turso_parser::ast::{Expr, SortOrder, SortedColumn};
|
||||
|
||||
use super::schema::{emit_schema_entry, SchemaEntryType, SQLITE_TABLEID};
|
||||
|
||||
@@ -350,16 +350,13 @@ fn resolve_sorted_columns<'a>(
|
||||
) -> crate::Result<Vec<((usize, &'a Column), SortOrder)>> {
|
||||
let mut resolved = Vec::with_capacity(cols.len());
|
||||
for sc in cols {
|
||||
let ident = normalize_ident(match sc.expr.as_ref() {
|
||||
let ident = match sc.expr.as_ref() {
|
||||
// SQLite supports indexes on arbitrary expressions, but we don't (yet).
|
||||
// See "How to use indexes on expressions" in https://www.sqlite.org/expridx.html
|
||||
Expr::Id(ast::Name::Ident(col_name))
|
||||
| Expr::Id(ast::Name::Quoted(col_name))
|
||||
| Expr::Name(ast::Name::Ident(col_name))
|
||||
| Expr::Name(ast::Name::Quoted(col_name)) => col_name,
|
||||
Expr::Id(col_name) | Expr::Name(col_name) => col_name.as_str(),
|
||||
_ => crate::bail_parse_error!("Error: cannot use expressions in CREATE INDEX"),
|
||||
});
|
||||
let Some(col) = table.get_column(&ident) else {
|
||||
};
|
||||
let Some(col) = table.get_column(ident) else {
|
||||
crate::bail_parse_error!(
|
||||
"Error: column '{ident}' does not exist in table '{}'",
|
||||
table.name
|
||||
|
||||
@@ -1740,7 +1740,7 @@ pub fn rewrite_partial_index_where(
|
||||
&mut |e: &mut ast::Expr| -> crate::Result<WalkControl> {
|
||||
match e {
|
||||
// NOTE: should not have ANY Expr::Columns bound to the expr
|
||||
Expr::Id(ast::Name::Ident(name)) | Expr::Id(ast::Name::Quoted(name)) => {
|
||||
Expr::Id(name) => {
|
||||
let normalized = normalize_ident(name.as_str());
|
||||
if let Some(reg) = col_reg(&normalized) {
|
||||
*e = Expr::Register(reg);
|
||||
|
||||
@@ -415,9 +415,7 @@ impl<'a> LogicalPlanBuilder<'a> {
|
||||
|
||||
// Convert Name to String
|
||||
fn name_to_string(name: &ast::Name) -> String {
|
||||
match name {
|
||||
ast::Name::Ident(s) | ast::Name::Quoted(s) => s.clone(),
|
||||
}
|
||||
name.as_str().to_string()
|
||||
}
|
||||
|
||||
// Build a SELECT statement
|
||||
|
||||
@@ -77,27 +77,22 @@ pub struct ConflictTarget {
|
||||
// Extract `(column, optional_collate)` from an ON CONFLICT target Expr.
|
||||
// Accepts: Id, Qualified, DoublyQualified, Parenthesized, Collate
|
||||
fn extract_target_key(e: &ast::Expr) -> Option<ConflictTarget> {
|
||||
use ast::Name::{Ident, Quoted};
|
||||
match e {
|
||||
ast::Expr::Collate(inner, c) => {
|
||||
let mut tk = extract_target_key(inner.as_ref())?;
|
||||
let cstr = match c {
|
||||
Ident(s) | Quoted(s) => s.as_str(),
|
||||
};
|
||||
let cstr = c.as_str();
|
||||
tk.collate = Some(cstr.to_ascii_lowercase());
|
||||
Some(tk)
|
||||
}
|
||||
ast::Expr::Parenthesized(v) if v.len() == 1 => extract_target_key(&v[0]),
|
||||
|
||||
ast::Expr::Id(Ident(name)) | ast::Expr::Id(Quoted(name)) => Some(ConflictTarget {
|
||||
col_name: normalize_ident(name),
|
||||
ast::Expr::Id(name) => Some(ConflictTarget {
|
||||
col_name: normalize_ident(name.as_str()),
|
||||
collate: None,
|
||||
}),
|
||||
// t.a or db.t.a: accept ident or quoted in the column position
|
||||
ast::Expr::Qualified(_, col) | ast::Expr::DoublyQualified(_, _, col) => {
|
||||
let cname = match col {
|
||||
Ident(s) | Quoted(s) => s.as_str(),
|
||||
};
|
||||
let cname = col.as_str();
|
||||
Some(ConflictTarget {
|
||||
col_name: normalize_ident(cname),
|
||||
collate: None,
|
||||
@@ -192,20 +187,19 @@ fn index_keys(idx: &Index) -> Vec<usize> {
|
||||
|
||||
/// Columns referenced by the partial WHERE (empty if none).
|
||||
fn partial_index_cols(idx: &Index, table: &Table) -> HashSet<usize> {
|
||||
use ast::{Expr, Name};
|
||||
use ast::Expr;
|
||||
let Some(expr) = &idx.where_clause else {
|
||||
return HashSet::new();
|
||||
};
|
||||
let mut out = HashSet::new();
|
||||
let _ = walk_expr(expr, &mut |e: &ast::Expr| -> crate::Result<WalkControl> {
|
||||
match e {
|
||||
Expr::Id(Name::Ident(n) | Name::Quoted(n)) => {
|
||||
Expr::Id(n) => {
|
||||
if let Some((i, _)) = table.get_column_by_name(&normalize_ident(n.as_str())) {
|
||||
out.insert(i);
|
||||
}
|
||||
}
|
||||
Expr::Qualified(ns, Name::Ident(c) | Name::Quoted(c))
|
||||
| Expr::DoublyQualified(_, ns, Name::Ident(c) | Name::Quoted(c)) => {
|
||||
Expr::Qualified(ns, c) | Expr::DoublyQualified(_, ns, c) => {
|
||||
// Only count columns that belong to this table
|
||||
let nsn = normalize_ident(ns.as_str());
|
||||
let tname = normalize_ident(table.get_name());
|
||||
@@ -891,7 +885,7 @@ fn rewrite_expr_to_registers(
|
||||
insertion: Option<&Insertion>,
|
||||
allow_excluded: bool,
|
||||
) -> crate::Result<WalkControl> {
|
||||
use ast::{Expr, Name};
|
||||
use ast::Expr;
|
||||
let table_name_norm = table_name.map(normalize_ident);
|
||||
|
||||
// Map a column name to a register within the row image at `base_start`.
|
||||
@@ -911,8 +905,7 @@ fn rewrite_expr_to_registers(
|
||||
e,
|
||||
&mut |expr: &mut ast::Expr| -> crate::Result<WalkControl> {
|
||||
match expr {
|
||||
Expr::Qualified(ns, Name::Ident(c) | Name::Quoted(c))
|
||||
| Expr::DoublyQualified(_, ns, Name::Ident(c) | Name::Quoted(c)) => {
|
||||
Expr::Qualified(ns, c) | Expr::DoublyQualified(_, ns, c) => {
|
||||
let ns = normalize_ident(ns.as_str());
|
||||
let c = normalize_ident(c.as_str());
|
||||
// Handle EXCLUDED.* if enabled
|
||||
@@ -940,7 +933,7 @@ fn rewrite_expr_to_registers(
|
||||
}
|
||||
}
|
||||
// Unqualified id -> row image (CURRENT/NEW depending on caller)
|
||||
Expr::Id(Name::Ident(name)) | Expr::Id(Name::Quoted(name)) => {
|
||||
Expr::Id(name) => {
|
||||
if let Some(r) = col_reg_from_row_image(&normalize_ident(name.as_str())) {
|
||||
*expr = Expr::Register(r);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ use super::{
|
||||
};
|
||||
use parking_lot::RwLock;
|
||||
use rand::{thread_rng, Rng};
|
||||
use turso_parser::ast;
|
||||
use turso_parser::ast::{self, Name};
|
||||
use turso_parser::parser::Parser;
|
||||
|
||||
use super::{
|
||||
@@ -5320,11 +5320,12 @@ pub fn op_function(
|
||||
|
||||
for column in &mut columns {
|
||||
match column.expr.as_mut() {
|
||||
ast::Expr::Id(ast::Name::Ident(id))
|
||||
| ast::Expr::Id(ast::Name::Quoted(id))
|
||||
if normalize_ident(id) == rename_from =>
|
||||
ast::Expr::Id(id)
|
||||
if normalize_ident(id.as_str()) == rename_from =>
|
||||
{
|
||||
*id = column_def.col_name.as_str().to_owned();
|
||||
*id = Name::Ident(
|
||||
column_def.col_name.as_str().to_owned(),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user