Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 509b927

Browse files
committed
test cases for DO, ANALYZE, VACUUM
1 parent 6f4fa59 commit 509b927

9 files changed

Lines changed: 2112 additions & 179 deletions

File tree

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Anywhere SQL hits a hot path: proxies, sidecars, migration tools, linters, etc.
1212

1313
#### Why this exists
1414

15-
libsqlglot was born out of a gap in the C++ ecosystem: the lack of native tooling for high-speed, hassle-free parsing & transpiling between dozens of SQL dialects.
15+
libsqlglot was born out of a gap in the C++ ecosystem: the lack of native tooling for efficient, high-volume and hassle-free parsing & transpilation between dozens of SQL dialects.
1616

1717
Inspired by the original [sqlglot](https://github.com/tobymao/sqlglot), which did the decade-long work of mapping 31+ SQL dialects into an elegant, universal AST. libsqlglot does the comparatively trivial work of compiling it: the algorithm was already O(n), the runtime wasn't.
1818

@@ -218,7 +218,7 @@ cmake --build build
218218

219219
## Architecture
220220

221-
Header-only design: you only pay for what you use. 19 header files, no `.cpp`. See `include/libsqlglot/` for the full layout. Core files: `parser.h` (3479 lines), `generator.h` (1913), `expression.h` (1248, 115 expression types). Entry point is `transpiler.h` (86 lines).
221+
Header-only design: you only pay for what you use. 19 header files, no `.cpp`. See `include/libsqlglot/` for the full layout. Core files: `parser.h` (4016 lines), `generator.h` (2092), `expression.h` (1376, 115 expression types). Entry point is `transpiler.h` (86 lines).
222222

223223
### Memory management
224224

@@ -587,6 +587,16 @@ These dialects inherit features from a compatible base dialect and add specific
587587
| Vertica | Vertica | PostgreSQL | CREATE PROJECTION for physical design, SEGMENTED BY HASH, columnar storage |
588588
| YugabyteDB | YugabyteDB | PostgreSQL | SPLIT INTO n TABLETS, distributed SQL, PostgreSQL compatibility |
589589

590+
## Contributing
591+
592+
# Contributing
593+
594+
libsqlglot is a solo project. Bug reports, test cases, and dialect edge cases are welcome via GitHub issues.
595+
596+
If you find a query that parses incorrectly, or a dialect transformation that produces wrong output, please open an issue with the input SQL, source dialect, target dialect, and expected output.
597+
598+
Pull requests are considered but there is no guarantee of merge. The codebase is intentionally small and opinionated.
599+
590600
## Licence
591601

592602
Apache 2.0

include/libsqlglot/expression.h

Lines changed: 135 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,29 +1165,157 @@ struct VacuumStmt : Expression {
11651165
: Expression(ExprType::VACUUM_STMT) {}
11661166
};
11671167

1168-
/// GRANT statement
1168+
/// GRANT statement - Production-grade with comprehensive privilege support
11691169
struct GrantStmt : Expression {
1170-
enum class PrivilegeType { SELECT, INSERT, UPDATE, DELETE, ALL, EXECUTE, USAGE };
1170+
// SQL Standard + Database-specific privileges
1171+
enum class PrivilegeType {
1172+
// Basic SQL Standard privileges
1173+
SELECT,
1174+
INSERT,
1175+
UPDATE,
1176+
DELETE,
1177+
TRUNCATE,
1178+
REFERENCES,
1179+
TRIGGER,
1180+
1181+
// DDL privileges
1182+
CREATE,
1183+
ALTER,
1184+
DROP,
1185+
1186+
// Database/Schema-level privileges
1187+
CONNECT,
1188+
TEMPORARY,
1189+
TEMP, // Alias for TEMPORARY
1190+
USAGE,
1191+
1192+
// Procedure/Function privileges
1193+
EXECUTE,
1194+
ROUTINE, // MySQL-style for procedures/functions
1195+
1196+
// Role/Administrative privileges
1197+
CREATEROLE,
1198+
CREATEDB,
1199+
REPLICATION,
1200+
BYPASSRLS, // Bypass row-level security (PostgreSQL)
1201+
1202+
// Table-specific column privileges
1203+
UPDATE_COLUMN, // UPDATE on specific columns
1204+
REFERENCES_COLUMN, // REFERENCES on specific columns
1205+
1206+
// Administrative
1207+
ALL, // ALL PRIVILEGES
1208+
ALL_PRIVILEGES, // Explicit ALL PRIVILEGES
1209+
1210+
// BigQuery-specific
1211+
BIGQUERY_READER,
1212+
BIGQUERY_EDITOR,
1213+
BIGQUERY_OWNER,
1214+
BIGQUERY_VIEWER,
1215+
1216+
// Snowflake-specific
1217+
OWNERSHIP,
1218+
OPERATE,
1219+
MONITOR,
1220+
MODIFY,
1221+
READ,
1222+
WRITE,
1223+
1224+
// Oracle-specific
1225+
INDEX,
1226+
DEBUG,
1227+
FLASHBACK,
1228+
1229+
// MySQL-specific
1230+
SHOW_VIEW,
1231+
CREATE_VIEW,
1232+
EVENT,
1233+
LOCK_TABLES,
1234+
RELOAD,
1235+
SHUTDOWN,
1236+
PROCESS,
1237+
FILE,
1238+
GRANT_OPTION,
1239+
SUPER,
1240+
1241+
// SQL Server-specific
1242+
CONTROL,
1243+
TAKE_OWNERSHIP,
1244+
IMPERSONATE,
1245+
VIEW_DEFINITION,
1246+
ALTER_ANY_USER,
1247+
ALTER_ANY_ROLE,
1248+
1249+
// Custom/Unrecognized (for forward compatibility)
1250+
CUSTOM
1251+
};
11711252

1172-
std::vector<PrivilegeType> privileges;
1173-
std::string object_type; // TABLE, DATABASE, SCHEMA, FUNCTION, etc.
1253+
struct ColumnPrivilege {
1254+
PrivilegeType privilege; // UPDATE or REFERENCES
1255+
std::vector<std::string> columns; // Column names
1256+
};
1257+
1258+
// Privileges
1259+
std::vector<PrivilegeType> privileges; // Global privileges
1260+
std::vector<ColumnPrivilege> column_privileges; // Column-level privileges
1261+
1262+
// Object specification
1263+
std::string object_type; // TABLE, DATABASE, SCHEMA, FUNCTION, SEQUENCE, etc.
11741264
std::string object_name;
1265+
std::string schema_name; // Optional schema qualifier
1266+
std::vector<std::string> object_list; // For multiple objects: GRANT ... ON table1, table2, table3
1267+
1268+
// Grantees
11751269
std::vector<std::string> grantees; // Users/roles to grant to
1176-
bool with_grant_option = false;
1270+
bool to_public = false; // GRANT ... TO PUBLIC
1271+
1272+
// Options
1273+
bool with_grant_option = false; // Allow grantees to grant privileges
1274+
bool with_admin_option = false; // For role grants (PostgreSQL/Oracle)
1275+
bool with_hierarchy_option = false; // For object hierarchy (SQL Server)
1276+
1277+
// Role grants (GRANT role TO user)
1278+
bool is_role_grant = false; // True if granting role membership
1279+
std::vector<std::string> roles; // Roles being granted
1280+
1281+
// Custom privileges (for extensibility)
1282+
std::vector<std::string> custom_privileges; // Unrecognized privilege names
11771283

11781284
GrantStmt()
11791285
: Expression(ExprType::GRANT_STMT) {}
11801286
};
11811287

1182-
/// REVOKE statement
1288+
/// REVOKE statement - Production-grade with comprehensive privilege support
11831289
struct RevokeStmt : Expression {
11841290
using PrivilegeType = GrantStmt::PrivilegeType;
1291+
using ColumnPrivilege = GrantStmt::ColumnPrivilege;
11851292

1293+
// Privileges
11861294
std::vector<PrivilegeType> privileges;
1295+
std::vector<ColumnPrivilege> column_privileges;
1296+
1297+
// Object specification
11871298
std::string object_type;
11881299
std::string object_name;
1300+
std::string schema_name;
1301+
std::vector<std::string> object_list;
1302+
1303+
// Grantees
11891304
std::vector<std::string> grantees;
1190-
bool cascade = false;
1305+
bool from_public = false; // REVOKE ... FROM PUBLIC
1306+
1307+
// Options
1308+
bool cascade = false; // CASCADE revoke (revoke dependents)
1309+
bool restrict = false; // RESTRICT (fail if dependents)
1310+
bool grant_option_for = false; // REVOKE GRANT OPTION FOR
1311+
bool admin_option_for = false; // REVOKE ADMIN OPTION FOR (roles)
1312+
1313+
// Role revokes
1314+
bool is_role_revoke = false;
1315+
std::vector<std::string> roles;
1316+
1317+
// Custom privileges
1318+
std::vector<std::string> custom_privileges;
11911319

11921320
RevokeStmt()
11931321
: Expression(ExprType::REVOKE_STMT) {}

0 commit comments

Comments
 (0)