/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_create_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 CREATE KEYSPACE statements. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #include "yb/yql/cql/ql/ptree/pt_create_keyspace.h" |
19 | | |
20 | | #include "yb/common/redis_constants_common.h" |
21 | | |
22 | | #include "yb/yql/cql/ql/ptree/sem_context.h" |
23 | | #include "yb/yql/cql/ql/ptree/yb_location.h" |
24 | | |
25 | | DECLARE_bool(use_cassandra_authentication); |
26 | | |
27 | | namespace yb { |
28 | | namespace ql { |
29 | | |
30 | | //-------------------------------------------------------------------------------------------------- |
31 | | |
32 | | PTCreateKeyspace::PTCreateKeyspace(MemoryContext *memctx, |
33 | | YBLocation::SharedPtr loc, |
34 | | const MCSharedPtr<MCString>& name, |
35 | | bool create_if_not_exists, |
36 | | const PTKeyspacePropertyListNode::SharedPtr& keyspace_properties) |
37 | | : TreeNode(memctx, loc), |
38 | | name_(name), |
39 | | create_if_not_exists_(create_if_not_exists), |
40 | 1.66k | keyspace_properties_(keyspace_properties) { |
41 | 1.66k | } |
42 | | |
43 | 1.61k | PTCreateKeyspace::~PTCreateKeyspace() { |
44 | 1.61k | } |
45 | | |
46 | 1.66k | CHECKED_STATUS PTCreateKeyspace::Analyze(SemContext *sem_context) { |
47 | 1.66k | if (*name_ == common::kRedisKeyspaceName) { |
48 | 1 | return sem_context->Error(loc(), |
49 | 1 | strings::Substitute("$0 is a reserved keyspace name", |
50 | 1 | common::kRedisKeyspaceName).c_str(), |
51 | 1 | ErrorCode::INVALID_ARGUMENTS); |
52 | 1 | } |
53 | | |
54 | 1.66k | if (FLAGS_use_cassandra_authentication) { |
55 | 912 | RETURN_NOT_OK(sem_context->CheckHasAllKeyspacesPermission(loc(), |
56 | 912 | PermissionType::CREATE_PERMISSION)); |
57 | 912 | } |
58 | | |
59 | 1.66k | if (keyspace_properties_ != nullptr) { |
60 | | // Process table properties. |
61 | 74 | RETURN_NOT_OK(keyspace_properties_->Analyze(sem_context)); |
62 | 74 | } |
63 | | |
64 | 1.64k | if (VLOG_IS_ON(3)) { |
65 | 0 | PrintSemanticAnalysisResult(sem_context); |
66 | 0 | } |
67 | | |
68 | 1.64k | return Status::OK(); |
69 | 1.66k | } |
70 | | |
71 | 0 | void PTCreateKeyspace::PrintSemanticAnalysisResult(SemContext *sem_context) { |
72 | 0 | MCString sem_output("\tKeyspace ", sem_context->PTempMem()); |
73 | 0 | sem_output += name(); |
74 | 0 | sem_output += (create_if_not_exists()? " IF NOT EXISTS" : ""); |
75 | 0 | VLOG(3) << "SEMANTIC ANALYSIS RESULT (" << loc() << "):\n" << sem_output; |
76 | 0 | } |
77 | | |
78 | | } // namespace ql |
79 | | } // namespace yb |