/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_dml_using_clause_element.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include "yb/yql/cql/ql/ptree/pt_dml_using_clause_element.h" |
15 | | |
16 | | #include "yb/common/ql_type.h" |
17 | | |
18 | | #include "yb/util/status.h" |
19 | | |
20 | | #include "yb/yql/cql/ql/ptree/pt_expr.h" |
21 | | #include "yb/yql/cql/ql/ptree/sem_context.h" |
22 | | #include "yb/yql/cql/ql/ptree/sem_state.h" |
23 | | #include "yb/yql/cql/ql/util/errcodes.h" |
24 | | |
25 | | namespace yb { |
26 | | namespace ql { |
27 | | |
28 | | namespace { |
29 | | |
30 | | constexpr const char* const kTtl = "ttl"; |
31 | | constexpr const char* const kTimestamp = "timestamp"; |
32 | | |
33 | | } |
34 | | |
35 | | PTDmlUsingClauseElement::PTDmlUsingClauseElement(MemoryContext *memctx, |
36 | | YBLocationPtr loc, |
37 | | const MCSharedPtr<MCString>& name, |
38 | | const PTExprPtr& value) |
39 | | : TreeNode(memctx, loc), |
40 | | name_(name), |
41 | 217 | value_(value) { |
42 | 217 | } |
43 | | |
44 | 198 | PTDmlUsingClauseElement::~PTDmlUsingClauseElement() { |
45 | 198 | } |
46 | | |
47 | 204 | Status PTDmlUsingClauseElement::Analyze(SemContext *sem_context) { |
48 | 204 | if (name_ == nullptr) { |
49 | 0 | return sem_context->Error( |
50 | 0 | this, |
51 | 0 | "Undefined parameter name in DML using clause element", |
52 | 0 | ErrorCode::INVALID_ARGUMENTS); |
53 | 0 | } |
54 | | |
55 | 204 | if (strcmp(name_->c_str(), kTtl) != 0 && strcmp(name_->c_str(), kTimestamp) != 0) { |
56 | 0 | return sem_context->Error( |
57 | 0 | this, |
58 | 0 | strings::Substitute("Invalid parameter $0, only $1 and $2 are supported", |
59 | 0 | name_->c_str(), kTtl, kTimestamp).c_str(), |
60 | 0 | ErrorCode::INVALID_ARGUMENTS); |
61 | 0 | } |
62 | | |
63 | 204 | if (value_ == nullptr) { |
64 | 0 | return sem_context->Error( |
65 | 0 | this, |
66 | 0 | strings::Substitute("Invalid value for parameter $0", name_->c_str()).c_str(), |
67 | 0 | ErrorCode::INVALID_ARGUMENTS); |
68 | 0 | } |
69 | | |
70 | 204 | RETURN_NOT_OK(value_->CheckRhsExpr(sem_context)); |
71 | | |
72 | 202 | SemState sem_state(sem_context); |
73 | 202 | if (strcmp(name_->c_str(), kTtl) == 0) { |
74 | 108 | sem_state.SetExprState(QLType::Create(INT32), InternalType::kInt32Value); |
75 | 108 | sem_state.set_bindvar_name(PTBindVar::ttl_bindvar_name()); |
76 | 94 | } else { |
77 | | // has to be timestamp. |
78 | 94 | DCHECK_EQ(0, strcmp(name_->c_str(), kTimestamp)); |
79 | 94 | sem_state.SetExprState(QLType::Create(INT64), InternalType::kInt64Value); |
80 | 94 | sem_state.set_bindvar_name(PTBindVar::timestamp_bindvar_name()); |
81 | 94 | } |
82 | | |
83 | 202 | RETURN_NOT_OK(value_->Analyze(sem_context)); |
84 | | |
85 | 194 | return Status::OK(); |
86 | 202 | } |
87 | | |
88 | 194 | bool PTDmlUsingClauseElement::IsTTL() const { |
89 | 194 | return strcmp(name_->c_str(), kTtl) == 0; |
90 | 194 | } |
91 | | |
92 | 94 | bool PTDmlUsingClauseElement::IsTimestamp() const { |
93 | 94 | return strcmp(name_->c_str(), kTimestamp) == 0; |
94 | 94 | } |
95 | | |
96 | | } // namespace ql |
97 | | } // namespace yb |