-
Notifications
You must be signed in to change notification settings - Fork 398
Add support for Presto #881
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
Merged
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package sqlancer.presto; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.math.RoundingMode; | ||
|
|
||
| public final class PrestoConstantUtils { | ||
|
|
||
| private PrestoConstantUtils() { | ||
| } | ||
|
|
||
| public static String removeNoneAscii(String str) { | ||
| return str.replaceAll("[^\\x00-\\x7F]", ""); | ||
| } | ||
|
|
||
| public static String removeNonePrintable(String str) { // All Control Char | ||
| return str.replaceAll("[\\p{C}]", ""); | ||
| } | ||
|
|
||
| public static String removeOthersControlChar(String str) { // Some Control Char | ||
| return str.replaceAll("[\\p{Cntrl}\\p{Cc}\\p{Cf}\\p{Co}\\p{Cn}]", ""); | ||
| } | ||
|
|
||
| public static String removeAllControlChars(String str) { | ||
| return removeOthersControlChar(removeNonePrintable(str)).replaceAll("[\\r\\n\\t]", ""); | ||
| } | ||
|
|
||
| public static BigDecimal getDecimal(double val, int scale, int precision) { | ||
| int part = precision - scale; | ||
| // long part | ||
| long lng = (long) val; | ||
| // decimal places | ||
| double d1 = val - lng; | ||
| String xStr = Long.toString(lng); | ||
| String substring = xStr.substring(xStr.length() - part); | ||
| long newX = substring.isEmpty() ? 0 : Long.parseLong(substring); | ||
| double finalD = newX + d1; | ||
| return new BigDecimal(finalD).setScale(scale, RoundingMode.CEILING); | ||
| } | ||
|
|
||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package sqlancer.presto; | ||
|
|
||
| import sqlancer.common.query.ExpectedErrors; | ||
|
|
||
| public final class PrestoErrors { | ||
|
|
||
| private PrestoErrors() { | ||
| } | ||
|
|
||
| public static void addExpressionErrors(ExpectedErrors errors) { | ||
| // Presto errors | ||
| errors.add("cannot be applied to"); | ||
| errors.add("LIKE expression must evaluate to a varchar"); | ||
| errors.add("JOIN ON clause must evaluate to a boolean"); | ||
| // errors.add("Unexpected parameters"); | ||
|
|
||
| // SELECT SUM(count) FROM (SELECT | ||
| // CAST((-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 | ||
| // IS NOT NULL AND | ||
| // -179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000) | ||
| // AS BIGINT)as count FROM t0) as res | ||
| errors.add("Decimal overflow"); | ||
| errors.add("multiplication overflow"); | ||
| errors.add("addition overflow"); | ||
| errors.add("subtraction overflow"); | ||
|
|
||
| // cast | ||
| // errors.add("Cannot cast"); | ||
| errors.add("Value cannot be cast to"); | ||
| errors.add("Cannot cast DECIMAL"); | ||
| errors.add("Cannot cast BIGINT"); | ||
| errors.add("Cannot cast INTEGER"); | ||
|
|
||
| // TODO: check | ||
| errors.add("io.airlift.slice.Slice cannot be cast to java.lang.Number"); | ||
| errors.add("Cannot cast java.lang.Long to io.airlift.slice.Slice"); | ||
| errors.add("Unexpected subquery expression in logical plan"); | ||
|
|
||
| // 9223372036854775808 | ||
| errors.add("Invalid numeric literal"); | ||
|
|
||
| errors.add("Division by zero"); | ||
| errors.add("/ by zero"); | ||
|
|
||
| errors.add("Cannot subtract hour, minutes or seconds from a date"); | ||
| errors.add("Cannot add hour, minutes or seconds to a date"); | ||
|
|
||
| errors.add("DECIMAL scale must be in range"); | ||
| errors.add("multiplication overflow"); | ||
| errors.add("addition overflow"); | ||
| errors.add("subtraction overflow"); | ||
| errors.add("Decimal overflow"); | ||
| errors.add("IN value and list items must be the same type"); | ||
| errors.add("is not a valid timestamp literal"); | ||
| errors.add("Unknown time-zone ID"); | ||
| errors.add("GROUP BY position"); | ||
|
|
||
| // ARRAY | ||
| errors.add("Unknown type: ARRAY"); | ||
| } | ||
|
|
||
| private static void addRegexErrors(ExpectedErrors errors) { | ||
| errors.add("missing ]"); | ||
| errors.add("missing )"); | ||
| errors.add("invalid escape sequence"); | ||
| errors.add("no argument for repetition operator: "); | ||
| errors.add("bad repetition operator"); | ||
| errors.add("trailing \\"); | ||
| errors.add("invalid perl operator"); | ||
| errors.add("invalid character class range"); | ||
| errors.add("width is not integer"); | ||
| } | ||
|
|
||
| private static void addFunctionErrors(ExpectedErrors errors) { | ||
| errors.add("SUBSTRING cannot handle negative lengths"); | ||
| errors.add("is undefined outside [-1,1]"); // ACOS etc | ||
| errors.add("invalid type specifier"); // PRINTF | ||
| errors.add("argument index out of range"); // PRINTF | ||
| errors.add("invalid format string"); // PRINTF | ||
| errors.add("number is too big"); // PRINTF | ||
| errors.add("Like pattern must not end with escape character!"); // LIKE | ||
| errors.add("Could not choose a best candidate function for the function call \"date_part"); // date_part | ||
| errors.add("extract specifier"); // date_part | ||
| errors.add("not recognized"); // date_part | ||
| errors.add("not supported"); // date_part | ||
| errors.add("Failed to cast"); | ||
| errors.add("Conversion Error"); | ||
| errors.add("Could not cast value"); | ||
| errors.add("Insufficient padding in RPAD"); // RPAD | ||
| errors.add("Could not choose a best candidate function for the function call"); // monthname | ||
| errors.add("expected a numeric precision field"); // ROUND | ||
| errors.add("with non-constant precision is not supported"); // ROUND | ||
| } | ||
|
|
||
| // TODO: cover presto error | ||
| public static void addInsertErrors(ExpectedErrors errors) { | ||
| addRegexErrors(errors); | ||
| addFunctionErrors(errors); | ||
|
|
||
| errors.add("NOT NULL constraint failed"); | ||
| errors.add("PRIMARY KEY or UNIQUE constraint violated"); | ||
| errors.add("duplicate key"); | ||
| errors.add("can't be cast because the value is out of range for the destination type"); | ||
| errors.add("Could not convert string"); | ||
| errors.add("Unimplemented type for cast"); | ||
| errors.add("field value out of range"); | ||
| errors.add("CHECK constraint failed"); | ||
| errors.add("Cannot explicitly insert values into rowid column"); // TODO: don't insert into rowid | ||
| errors.add(" Column with name rowid does not exist!"); // currently, there doesn't seem to way to determine if | ||
| // the table has a primary key | ||
| errors.add("Could not cast value"); | ||
| errors.add("create unique index, table contains duplicate data"); | ||
| errors.add("Failed to cast"); | ||
|
|
||
| errors.add("Values rows have mismatched types"); | ||
| errors.add("Mismatch at column"); | ||
| errors.add("This connector does not support updates or deletes"); | ||
| errors.add("Values rows have mismatched types"); | ||
| errors.add("Invalid numeric literal"); | ||
|
|
||
| } | ||
|
|
||
| public static void addGroupByErrors(ExpectedErrors errors) { | ||
| errors.add("must be an aggregate expression or appear in GROUP BY clause"); | ||
| } | ||
|
|
||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package sqlancer.presto; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import sqlancer.common.ast.newast.Node; | ||
| import sqlancer.presto.ast.PrestoExpression; | ||
|
|
||
| public final class PrestoExpressionToNode { | ||
|
|
||
| private PrestoExpressionToNode() { | ||
|
|
||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static Node<PrestoExpression> cast(PrestoExpression expression) { | ||
| return (Node<PrestoExpression>) expression; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public static List<Node<PrestoExpression>> casts(List<PrestoExpression> expressions) { | ||
| return expressions.stream().map(e -> (Node<PrestoExpression>) e).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package sqlancer.presto; | ||
|
|
||
| import java.sql.SQLException; | ||
|
|
||
| import sqlancer.SQLGlobalState; | ||
|
|
||
| public class PrestoGlobalState extends SQLGlobalState<PrestoOptions, PrestoSchema> { | ||
|
|
||
| @Override | ||
| protected PrestoSchema readSchema() throws SQLException { | ||
| return PrestoSchema.fromConnection(getConnection(), getDatabaseName()); | ||
| } | ||
| } |
Oops, something went wrong.
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.
This looks like an internal error?
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.
There are some errors that occur in certain versions of Presto.
Some of them are analyzed by the Presto team and they will not be addressed in the near future.
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.
In this case, I'd suggest using the pattern described at https://github.com/sqlancer/sqlancer/blob/f852f8cc08a98db34d40d20011b7c8fe47abf453/CONTRIBUTING.md#unfixed-bugs.