Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SetStmt.java
Go to the documentation of this file.
1 // Copyright 2014 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.cloudera.impala.analysis;
16 
17 import com.cloudera.impala.thrift.TSetQueryOptionRequest;
18 import com.google.common.base.Preconditions;
19 
23 public class SetStmt extends StatementBase {
24  private final String key_;
25  private final String value_;
26 
27  // This key is deprecated in CDH5.2; COMPRESSION_CODEC_KEY replaces this
28  private static final String DEPRECATED_PARQUET_CODEC_KEY = "PARQUET_COMPRESSION_CODEC";
29  private static final String COMPRESSION_CODEC_KEY = "COMPRESSION_CODEC";
30 
31  // maps the given key name to a key defined in the thrift file
32  private static String resolveThriftKey(String key) {
33  if (key.toLowerCase().equals(DEPRECATED_PARQUET_CODEC_KEY.toLowerCase())) {
34  return COMPRESSION_CODEC_KEY;
35  }
36  return key;
37  }
38 
39  public SetStmt(String key, String value) {
40  Preconditions.checkArgument((key == null) == (value == null));
41  Preconditions.checkArgument(key == null || !key.isEmpty());
42  key_ = key;
43  value_ = value;
44  }
45 
46  @Override
47  public String toSql() {
48  if (key_ == null) return "SET";
49  Preconditions.checkNotNull(value_);
50  return "SET " + ToSqlUtils.getIdentSql(key_) + "='" + value_ + "'";
51  }
52 
53  @Override
54  public void analyze(Analyzer analyzer) {
55  // Query option key is validated by the backend.
56  }
57 
58  public TSetQueryOptionRequest toThrift() {
59  TSetQueryOptionRequest request = new TSetQueryOptionRequest();
60  if (key_ != null) {
61  request.setKey(resolveThriftKey(key_));
62  request.setValue(value_);
63  }
64  return request;
65  }
66 }
TSetQueryOptionRequest toThrift()
Definition: SetStmt.java:58
static final String COMPRESSION_CODEC_KEY
Definition: SetStmt.java:29
static String resolveThriftKey(String key)
Definition: SetStmt.java:32
void analyze(Analyzer analyzer)
Definition: SetStmt.java:54
SetStmt(String key, String value)
Definition: SetStmt.java:39
static final String DEPRECATED_PARQUET_CODEC_KEY
Definition: SetStmt.java:28