Skip to main content

reifydb_core/error/diagnostic/
query.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::{error::Diagnostic, fragment::Fragment};
5
6pub fn column_not_found(fragment: Fragment) -> Diagnostic {
7	Diagnostic {
8		code: "QUERY_001".to_string(),
9		statement: None,
10		message: "column not found".to_string(),
11		fragment,
12		label: Some("this column does not exist in the current context".to_string()),
13		help: Some("check for typos or ensure the column is defined in the input".to_string()),
14		column: None,
15		notes: vec![],
16		cause: None,
17		operator_chain: None,
18	}
19}
20
21pub fn extend_duplicate_column(column_name: &str) -> Diagnostic {
22	Diagnostic {
23		code: "EXTEND_002".to_string(),
24		statement: None,
25		message: format!("Cannot extend with duplicate column name '{}'", column_name),
26		fragment: Fragment::None,
27		label: Some("column already exists in the current frame".to_string()),
28		help: Some("Use a different column name or remove the existing column first".to_string()),
29		column: None,
30		notes: vec![
31			"EXTEND operation cannot add columns that already exist in the frame".to_string(),
32			"Each column name must be unique within the result frame".to_string(),
33			"Consider using MAP if you want to replace existing columns".to_string(),
34		],
35		cause: None,
36		operator_chain: None,
37	}
38}
39
40pub fn unsupported_source_qualification(fragment: Fragment, name: &str) -> Diagnostic {
41	Diagnostic {
42		code: "QUERY_002".to_string(),
43		statement: None,
44		message: format!("Source qualification '{}' is not supported in RQL expressions", name),
45		fragment,
46		label: Some("source qualification is only allowed for join aliases in ON clauses".to_string()),
47		help: Some("Remove the qualification or use it only with a join alias in the ON clause".to_string()),
48		column: None,
49		notes: vec![
50			"RQL uses a dataframe-centered approach where each operation produces a new dataframe"
51				.to_string(),
52			"Source qualifications are not needed as columns are unambiguous in the dataframe".to_string(),
53			"Only join aliases can be used for qualification within ON clauses to disambiguate columns"
54				.to_string(),
55		],
56		cause: None,
57		operator_chain: None,
58	}
59}
60
61pub fn join_column_alias_error(fragment: Fragment, message: &str) -> Diagnostic {
62	Diagnostic {
63		code: "QUERY_003".to_string(),
64		statement: None,
65		message: format!("Join column alias error: {}", message),
66		fragment,
67		label: Some("invalid column qualification in using clause".to_string()),
68		help: Some("In each pair, exactly one expression should reference the join alias".to_string()),
69		column: None,
70		notes: vec![
71			"Example: using (id, orders.user_id) where 'orders' is the join alias".to_string(),
72			"Unqualified columns refer to the current dataframe".to_string(),
73		],
74		cause: None,
75		operator_chain: None,
76	}
77}