-
Notifications
You must be signed in to change notification settings - Fork 72
CBL-6240: Align with server SQL++ reserved words #2386
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
Open
jianminzhao
wants to merge
2
commits into
master
Choose a base branch
from
cbl-6240
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,10 @@ | |
| #pragma once | ||
| #include "fleece/Mutable.hh" | ||
| #include "Any.hh" | ||
| #include "Logging.hh" | ||
| #include <algorithm> | ||
| #include <array> | ||
| #include <unordered_set> | ||
| #include <sstream> | ||
| #include <typeinfo> | ||
| #include <utility> | ||
|
|
@@ -204,6 +206,13 @@ namespace litecore::n1ql { | |
| return str; | ||
| } | ||
|
|
||
| static bool isServerReservedWord(std::string word); | ||
|
|
||
| static string warnOnServerReservedWord(const char* input) { | ||
| if ( isServerReservedWord(input) ) { Warn(R"("%s" is a reserved word in the Server SQL++)", input); } | ||
| return input; | ||
| } | ||
|
|
||
| // Property-path operations: | ||
|
|
||
| static string quoteIdentity(string id) { | ||
|
|
@@ -349,6 +358,66 @@ namespace litecore::n1ql { | |
| return collate; | ||
| } | ||
|
|
||
| // constexpr const char* UnabridgedServerReservedWords = | ||
| // "ADVISE ALL ALTER ANALYZE ARRAY AT BEGIN BINARY BOOLEAN BREAK BUCKET BUILD CACHE CALL CAST CLUSTER " | ||
| // "COLLECTION COMMIT COMMITTED CONNECT CONTINUE CORRELATED COVER CREATE CURRENT" | ||
| // " CYCLE DATABASE DATASET DATASTORE DECLARE DECREMENT DEFAULT DELETE DERIVED DESCRIBE DO DROP EACH ELEMENT " | ||
| // "ESCAPE EXCEPT EXCLUDE EXECUTE EXISTS EXPLAIN FETCH FILTER FIRST FLATTEN FLATTEN_KEYS" | ||
| // " FLUSH FOLLOWING FOR FORCE FTS FUNCTION GOLANG GRANT GROUPS GSI HASH IF IGNORE ILIKE INCLUDE INCREMENT " | ||
| // "INDEX INFER INLINE INSERT INTERSECT INTO ISOLATION JAVASCRIPT KEY" | ||
| // " KEYS KEYSPACE KNOWN LANGUAGE LAST LATERAL LET LETTING LEVEL LSM MAP MAPPING MATCHED MATERIALIZED " | ||
| // "MAXVALUE MERGE MINUS MINVALUE NAMESPACE NAMESPACE_ID NEST NEXT NEXTVAL NL NO" | ||
| // " NOT_A_TOKEN NTH_VALUE NULLS NUMBER OBJECT OPTION OPTIONS OTHERS OVER PARSE PARTITION PASSWORD PATH POOL " | ||
| // "PRECEDING PREPARE PREV PREVIOUS PREVVAL PRIMARY PRIVATE PRIVILEGE PROBE PROCEDURE PUBLIC" | ||
| // " RANGE RAW READ REALM RECURSIVE REDUCE RENAME REPLACE RESPECT RESTART RESTRICT RETURN RETURNING REVOKE " | ||
| // "ROLE ROLES ROLLBACK ROW ROWS SAVEPOINT SCHEMA SCOPE SELF SEMI SEQUENCE" | ||
| // " SET SHOW SOME START STATISTICS STRING SYSTEM TIES TO TRAN TRANSACTION TRIGGER TRUNCATE UNBOUNDED UNDER " | ||
| // "UNION UNIQUE UNKNOWN UNSET UPDATE UPSERT USE USER USERS VALIDATE" | ||
| // " VALUE VALUES VECTOR VIA VIEW WHILE WINDOW WITH WITHIN WORK XOR"; | ||
|
|
||
| constexpr const char* kServerReservedWords = | ||
| " ALL ARRAY AT BEGIN CAST CORRELATED COVER CURRENT" | ||
| " DECREMENT DEFAULT DERIVED DESCRIBE DO EACH ELEMENT ESCAPE" | ||
| " EXCEPT EXCLUDE EXECUTE EXISTS EXPLAIN FETCH FILTER FIRST" | ||
| " FLATTEN FLATTEN_KEYS FOLLOWING FOR FORCE FUNCTION GRANT GROUPS" | ||
| " HASH IF IGNORE ILIKE INCLUDE INCREMENT INDEX INFER" | ||
| " INLINE INTERSECT ISOLATION KEY KEYS KEYSPACE KNOWN LAST" | ||
| " LATERAL LET LETTING LEVEL LSM MAP MAPPING MATCHED" | ||
| " MATERIALIZED MAXVALUE MERGE MINUS MINVALUE NAMESPACE NAMESPACE_ID NEST" | ||
| " EXT NEXTVAL NL NO NOT_A_TOKEN NTH_VALUE NULLS NUMBER" | ||
| " OBJECT OPTION OPTIONS OTHERS OVER PARSE PARTITION PASSWORD" | ||
| " PATH POOL PRECEDING PREPARE PREV PREVIOUS PREVVAL PRIMARY" | ||
| " PRIVATE PRIVILEGE PROBE PROCEDURE PUBLIC RANGE RAW READ" | ||
| " REALM RECURSIVE REDUCE RENAME REPLACE RESPECT RESTART RESTRICT" | ||
| " RETURN RETURNING REVOKE ROLE ROLES ROLLBACK ROW ROWS" | ||
| " SAVEPOINT SCHEMA SCOPE SELF SEMI SEQUENCE SHOW SOME" | ||
| " START STATISTICS STRING SYSTEM TIES TO TRAN TRIGGER" | ||
| " TRUNCATE UNBOUNDED UNDER UNION UNIQUE UNKNOWN UNSET UPDATE" | ||
| " UPSERT USE USER USERS VALIDATE VALUE VALUES VECTOR" | ||
| " VIA VIEW WHILE WINDOW WITH WITHIN WORK XOR"; | ||
|
|
||
| bool isServerReservedWord(std::string word) { | ||
| static std::unordered_set<std::string_view> serverReserved; | ||
| if ( serverReserved.empty() ) { | ||
| const char* p = kServerReservedWords; | ||
| const char* start = nullptr; | ||
| for ( ; *p != '\0'; ++p ) { | ||
| if ( *p == ' ' ) { | ||
| if ( start != nullptr ) { | ||
| //start -> p | ||
| serverReserved.emplace(start, p); | ||
| start = nullptr; | ||
| } | ||
| } else if ( start == nullptr ) { | ||
| start = p; | ||
| } | ||
| } | ||
| if ( start != nullptr ) { serverReserved.emplace(start, p); } | ||
|
Comment on lines
+402
to
+415
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use /** Splits the string at occurrences of `separator` and calls the callback for each piece.
There may be empty pieces, if the separator occurs at the start or end or twice in a row. */
void split(std::string_view str, std::string_view separator, fleece::function_ref<void(std::string_view)> callback);You'll need a consistent delimiter between words though, probably a single space. |
||
| } | ||
| uppercase(word); | ||
| return serverReserved.contains(word); | ||
| } | ||
|
|
||
| } // namespace litecore::n1ql | ||
|
|
||
| // The code generator produces some unreachable code; keep Clang from warning about it: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.