/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_use_keyspace.cc
Line | Count | Source (jump to first uncovered line) |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. 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 distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | // Treenode definitions for USE KEYSPACE statements. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #include "yb/yql/cql/ql/ptree/pt_use_keyspace.h" |
19 | | |
20 | | #include "yb/common/redis_constants_common.h" |
21 | | |
22 | | #include "yb/util/status.h" |
23 | | |
24 | | #include "yb/yql/cql/ql/ptree/sem_context.h" |
25 | | #include "yb/yql/cql/ql/ptree/yb_location.h" |
26 | | #include "yb/yql/cql/ql/util/errcodes.h" |
27 | | |
28 | | namespace yb { |
29 | | namespace ql { |
30 | | |
31 | | //-------------------------------------------------------------------------------------------------- |
32 | | |
33 | | PTUseKeyspace::PTUseKeyspace(MemoryContext *memctx, |
34 | | YBLocation::SharedPtr loc, |
35 | | const MCSharedPtr<MCString>& name) |
36 | | : TreeNode(memctx, loc), |
37 | 4.21k | name_(name) { |
38 | 4.21k | } |
39 | | |
40 | 4.16k | PTUseKeyspace::~PTUseKeyspace() { |
41 | 4.16k | } |
42 | | |
43 | 4.21k | CHECKED_STATUS PTUseKeyspace::Analyze(SemContext *sem_context) { |
44 | 4.21k | if (*name_ == common::kRedisKeyspaceName) { |
45 | 1 | return sem_context->Error(loc(), |
46 | 1 | strings::Substitute("$0 is a reserved keyspace name", |
47 | 1 | common::kRedisKeyspaceName).c_str(), |
48 | 1 | ErrorCode::INVALID_ARGUMENTS); |
49 | 1 | } |
50 | | |
51 | 4.20k | if (VLOG_IS_ON(3)) { |
52 | 0 | PrintSemanticAnalysisResult(sem_context); |
53 | 0 | } |
54 | | |
55 | 4.20k | return Status::OK(); |
56 | 4.20k | } |
57 | | |
58 | 0 | void PTUseKeyspace::PrintSemanticAnalysisResult(SemContext *sem_context) { |
59 | 0 | MCString sem_output("\tKeyspace ", sem_context->PTempMem()); |
60 | 0 | sem_output += name(); |
61 | 0 | VLOG(3) << "SEMANTIC ANALYSIS RESULT (" << loc() << "):\n" << sem_output; |
62 | 0 | } |
63 | | |
64 | 8.45k | const char* PTUseKeyspace::name() const { |
65 | 8.45k | return name_->c_str(); |
66 | 8.45k | } |
67 | | |
68 | | } // namespace ql |
69 | | } // namespace yb |