mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(redshift): add the SUPER and VARBYTE types and their functions (#8571)
This commit is contained in:
1 parent
f0ee5d44a0
commit
4f623d7b50
7 files changed
+526
No files matched your search
@@ -68,6 +68,21 @@ public final class RedshiftSqlInterceptor {
|
||||
/** {@code ENCODE <codec>} where {@code <codec>} is an actual Redshift column encoding or {@code AUTO}. */
|
||||
private static final Pattern ENCODE_PATTERN = Pattern.compile(
|
||||
"(?i)\\bENCODE\\s+(RAW|AZ64|BYTEDICT|DELTA32K|DELTA|LZO|MOSTLY8|MOSTLY16|MOSTLY32|RUNLENGTH|TEXT255|TEXT32K|ZSTD|AUTO)\\b");
|
||||
/** Whitespace and SQL comments, which may sit between the parts of a column definition. */
|
||||
private static final String GAP = "(?:\\s|/\\*.*?\\*/|--[^\\n]*(?:\\n|$))";
|
||||
/**
|
||||
* {@code VARBYTE(n)}, {@code VARBINARY(n)} and {@code BINARY VARYING(n)}, and the two aliases without a length, as
|
||||
* the type of a column: the {@code varbyte} domain takes no length, and PostgreSQL has no type of the other names.
|
||||
* A type is only the word after a column's name, and a column's definition only starts after the {@code (} or
|
||||
* {@code ,} of a column list or after {@code ADD [COLUMN] [IF NOT EXISTS]}. A column called {@code varbinary}, a
|
||||
* {@code RENAME COLUMN a TO varbinary} and the like are never in that position. Group 1 is what leads up to the
|
||||
* type, kept as it is.
|
||||
*/
|
||||
private static final Pattern VARBYTE_TYPE_PATTERN = Pattern.compile(
|
||||
"(?is)((?:[(,]|\\bADD\\s+(?:COLUMN\\s+)?+(?:IF\\s+NOT\\s+EXISTS\\s+)?+)" + GAP + "*(?:\"[^\"]+\"|\\w+)" + GAP + "+)"
|
||||
+ "(?:VARBYTE|VARBINARY|BINARY\\s+VARYING)(?:\\s*\\(\\s*\\d+\\s*\\))?(?=[\\s,)]|/\\*|--|$)");
|
||||
/** A table made from a query has no column types to rewrite, only select lists whose aliases could look like one. */
|
||||
private static final Pattern TABLE_FROM_QUERY_PATTERN = Pattern.compile("(?is)\\bAS\\s*\\(?\\s*(?:SELECT|WITH)\\b");
|
||||
private static final Pattern DOUBLE_COMMA_PATTERN = Pattern.compile(",(?:\\s*,)+");
|
||||
private static final Pattern COMMA_CLOSE_PAREN_PATTERN = Pattern.compile(",\\s*\\)");
|
||||
|
||||
@@ -113,6 +128,9 @@ public final class RedshiftSqlInterceptor {
|
||||
s = KEY_COLUMN_CONSTRAINT_PATTERN.matcher(s).replaceAll("");
|
||||
s = TABLE_LEVEL_KEY_IDENT_PATTERN.matcher(s).replaceAll("");
|
||||
s = ENCODE_PATTERN.matcher(s).replaceAll("");
|
||||
if (!TABLE_FROM_QUERY_PATTERN.matcher(s).find()) {
|
||||
s = VARBYTE_TYPE_PATTERN.matcher(s).replaceAll("$1varbyte");
|
||||
}
|
||||
s = DOUBLE_COMMA_PATTERN.matcher(s).replaceAll(",");
|
||||
s = COMMA_CLOSE_PAREN_PATTERN.matcher(s).replaceAll(")");
|
||||
return s;
|
||||
|
||||
Reference in new issue
Block a user