Representation of a SET query options statement.
| 26 | * Representation of a SET query options statement. |
| 27 | */ |
| 28 | public class SetStmt extends StatementBase { |
| 29 | private final String key_; |
| 30 | private final String value_; |
| 31 | private final TQueryOptionType queryOptionType_; |
| 32 | |
| 33 | // This key is deprecated in Impala 2.0; COMPRESSION_CODEC_KEY replaces this |
| 34 | private static final String DEPRECATED_PARQUET_CODEC_KEY = "PARQUET_COMPRESSION_CODEC"; |
| 35 | private static final String COMPRESSION_CODEC_KEY = "COMPRESSION_CODEC"; |
| 36 | |
| 37 | // maps the given key name to a key defined in the thrift file |
| 38 | private static String resolveThriftKey(String key) { |
| 39 | if (key.toLowerCase().equals(DEPRECATED_PARQUET_CODEC_KEY.toLowerCase())) { |
| 40 | return COMPRESSION_CODEC_KEY; |
| 41 | } |
| 42 | return key; |
| 43 | } |
| 44 | |
| 45 | public SetStmt(String key, String value, TQueryOptionType queryOptionType) { |
| 46 | Preconditions.checkArgument((key == null) == (value == null)); |
| 47 | Preconditions.checkArgument(key == null || !key.isEmpty()); |
| 48 | Preconditions.checkArgument( |
| 49 | queryOptionType != TQueryOptionType.SET_ALL || (key == null && value == null)); |
| 50 | key_ = key; |
| 51 | value_ = value; |
| 52 | queryOptionType_ = queryOptionType; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String toSql(ToSqlOptions options) { |
| 57 | if (queryOptionType_ == TQueryOptionType.UNSET_ALL) { |
| 58 | return "UNSET ALL"; |
| 59 | } |
| 60 | if (key_ == null) { |
| 61 | if (queryOptionType_ == TQueryOptionType.SET_ALL) return "SET ALL"; |
| 62 | return "SET"; |
| 63 | } |
| 64 | Preconditions.checkNotNull(value_); |
| 65 | return "SET " + ToSqlUtils.getIdentSql(key_) + "='" + value_ + "'"; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void analyze(Analyzer analyzer) { |
| 70 | // Query option key is validated by the backend. |
| 71 | } |
| 72 | |
| 73 | public TSetQueryOptionRequest toThrift() { |
| 74 | TSetQueryOptionRequest request = new TSetQueryOptionRequest(); |
| 75 | if (key_ != null) { |
| 76 | request.setKey(resolveThriftKey(key_)); |
| 77 | request.setValue(value_); |
| 78 | } |
| 79 | request.setQuery_option_type(queryOptionType_); |
| 80 | return request; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public boolean requiresHmsMetadata() { return false; } |
| 85 | } |
nothing calls this directly
no outgoing calls
no test coverage detected