Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
NullLiteral.java
Go to the documentation of this file.
1 // Copyright 2012 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 
18 import com.cloudera.impala.thrift.TExprNode;
19 import com.cloudera.impala.thrift.TExprNodeType;
20 import com.google.common.base.Objects;
21 import com.google.common.base.Preconditions;
22 
23 public class NullLiteral extends LiteralExpr {
24 
25  public NullLiteral() {
26  type_ = Type.NULL;
27  }
28 
32  protected NullLiteral(NullLiteral other) {
33  super(other);
34  }
35 
39  public static NullLiteral create(Type type) {
40  NullLiteral l = new NullLiteral();
41  l.analyzeNoThrow(null);
42  l.uncheckedCastTo(type);
43  return l;
44  }
45 
46  @Override
47  public boolean equals(Object obj) {
48  if (!super.equals(obj)) return false;
49  return obj instanceof NullLiteral;
50  }
51 
52  @Override
53  public String toSqlImpl() { return getStringValue(); }
54 
55  @Override
56  public String debugString() {
57  return Objects.toStringHelper(this).addValue(super.debugString()).toString();
58  }
59 
60  @Override
61  public String getStringValue() { return "NULL"; }
62 
63  @Override
64  protected Expr uncheckedCastTo(Type targetType) {
65  Preconditions.checkState(targetType.isValid());
66  type_ = targetType;
67  return this;
68  }
69 
70  @Override
71  protected void toThrift(TExprNode msg) {
72  msg.node_type = TExprNodeType.NULL_LITERAL;
73  }
74 
75  @Override
76  public Expr clone() { return new NullLiteral(this); }
77 
78  @Override
79  protected void resetAnalysisState() {
80  super.resetAnalysisState();
81  type_ = Type.NULL;
82  }
83 }
static final ScalarType NULL
Definition: Type.java:45
static NullLiteral create(Type type)