/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_insert_json_clause.h
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 | | // Tree node definitions for INSERT INTO ... JSON clause. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #ifndef YB_YQL_CQL_QL_PTREE_PT_INSERT_JSON_CLAUSE_H_ |
19 | | #define YB_YQL_CQL_QL_PTREE_PT_INSERT_JSON_CLAUSE_H_ |
20 | | |
21 | | #include <boost/optional.hpp> |
22 | | #include <rapidjson/document.h> |
23 | | |
24 | | #include "yb/util/status.h" |
25 | | |
26 | | #include "yb/yql/cql/ql/ptree/pt_dml.h" |
27 | | #include "yb/yql/cql/ql/ptree/tree_node.h" |
28 | | |
29 | | namespace yb { |
30 | | namespace ql { |
31 | | |
32 | | class PTInsertJsonClause: public PTCollection { |
33 | | public: |
34 | | // Public types. |
35 | | typedef MCSharedPtr<PTInsertJsonClause> SharedPtr; |
36 | | typedef MCSharedPtr<const PTInsertJsonClause> SharedPtrConst; |
37 | | |
38 | | // Constructor and destructor. |
39 | | PTInsertJsonClause(MemoryContext* memctx, |
40 | | const YBLocationPtr& loc, |
41 | | const PTExprPtr& json_expr, |
42 | | bool default_null); |
43 | | virtual ~PTInsertJsonClause(); |
44 | | |
45 | | template<typename... TypeArgs> |
46 | | inline static PTInsertJsonClause::SharedPtr MakeShared(MemoryContext* memctx, |
47 | 86 | TypeArgs&& ... args) { |
48 | 86 | return MCMakeShared<PTInsertJsonClause>(memctx, std::forward<TypeArgs>(args)...); |
49 | 86 | } std::__1::shared_ptr<yb::ql::PTInsertJsonClause> yb::ql::PTInsertJsonClause::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)7, (yb::DataType)5, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&, bool&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTExprConst<(yb::QLValuePB::ValueCase)7, (yb::DataType)5, std::__1::shared_ptr<std::__1::basic_string<char, std::__1::char_traits<char>, yb::internal::ArenaAllocatorBase<char, yb::internal::ArenaTraits> > >, yb::ql::PTLiteralString> >&, bool&) Line | Count | Source | 47 | 16 | TypeArgs&& ... args) { | 48 | 16 | return MCMakeShared<PTInsertJsonClause>(memctx, std::forward<TypeArgs>(args)...); | 49 | 16 | } |
std::__1::shared_ptr<yb::ql::PTInsertJsonClause> yb::ql::PTInsertJsonClause::MakeShared<std::__1::shared_ptr<yb::ql::Location>, std::__1::shared_ptr<yb::ql::PTExpr>&, bool&>(yb::internal::ArenaBase<yb::internal::ArenaTraits>*, std::__1::shared_ptr<yb::ql::Location>&&, std::__1::shared_ptr<yb::ql::PTExpr>&, bool&) Line | Count | Source | 47 | 70 | TypeArgs&& ... args) { | 48 | 70 | return MCMakeShared<PTInsertJsonClause>(memctx, std::forward<TypeArgs>(args)...); | 49 | 70 | } |
|
50 | | |
51 | | // Node type. |
52 | 157 | TreeNodeOpcode opcode() const override { |
53 | 157 | return TreeNodeOpcode::kPTInsertJsonClause; |
54 | 157 | } |
55 | | |
56 | | // Node semantics analysis. |
57 | | CHECKED_STATUS Analyze(SemContext* sem_context) override; |
58 | | void PrintSemanticAnalysisResult(SemContext* sem_context); |
59 | | |
60 | | // Initialize this clause with JSON string and parsed JSON document. |
61 | | // Note that you have to std::move the document here. |
62 | | CHECKED_STATUS PreExecInit(const std::string& json_string, |
63 | 77 | rapidjson::Document json_document) { |
64 | 77 | DCHECK(!json_document_) << "Double call to PreExecInit!"0 ; |
65 | 77 | DCHECK(json_document.IsObject()) << "Supplied JSON should be an object"0 ; |
66 | 77 | json_document_ = std::move(json_document); |
67 | 77 | json_string_ = json_string; |
68 | 77 | return Status::OK(); |
69 | 77 | } |
70 | | |
71 | 384 | bool IsDefaultNull() const { |
72 | 384 | return default_null_; |
73 | 384 | } |
74 | | |
75 | 240 | const PTExprPtr& Expr() const { |
76 | 240 | return json_expr_; |
77 | 240 | } |
78 | | |
79 | 0 | const std::string& JsonString() const { |
80 | 0 | DCHECK(json_document_) << "JSON not initialized!"; |
81 | 0 | return json_string_; |
82 | 0 | } |
83 | | |
84 | 77 | const rapidjson::Document& JsonDocument() const { |
85 | 77 | DCHECK(json_document_) << "JSON not initialized!"0 ; |
86 | 77 | return *json_document_; |
87 | 77 | } |
88 | | |
89 | | private: |
90 | | // Whether non-mentioned columns should be set to NULL, or left unchanged |
91 | | bool default_null_; |
92 | | |
93 | | // Expression representing raw JSON string, either a string constant or a bind variable. |
94 | | const PTExprPtr json_expr_; |
95 | | |
96 | | // Raw JSON string, only available after being set via PreExecInit. |
97 | | std::string json_string_; |
98 | | |
99 | | // Parsed JSON object, only available after being set via PreExecInit. Guaranteed to be an Object. |
100 | | boost::optional<rapidjson::Document> json_document_; |
101 | | }; |
102 | | |
103 | | } // namespace ql |
104 | | } // namespace yb |
105 | | |
106 | | #endif // YB_YQL_CQL_QL_PTREE_PT_INSERT_JSON_CLAUSE_H_ |