YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/statement.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
// This class represents a SQL statement.
16
//--------------------------------------------------------------------------------------------------
17
18
#ifndef YB_YQL_CQL_QL_STATEMENT_H_
19
#define YB_YQL_CQL_QL_STATEMENT_H_
20
21
#include "yb/yql/cql/ql/ptree/parse_tree.h"
22
#include "yb/yql/cql/ql/util/statement_params.h"
23
#include "yb/yql/cql/ql/util/statement_result.h"
24
25
#include "yb/util/monotime.h"
26
27
namespace yb {
28
namespace ql {
29
30
class QLProcessor;
31
32
class Statement {
33
 public:
34
  // Public types.
35
  typedef std::unique_ptr<Statement> UniPtr;
36
  typedef std::unique_ptr<const Statement> UniPtrConst;
37
38
  // Constructors.
39
  Statement(const std::string& keyspace, const std::string& text);
40
  virtual ~Statement();
41
42
  // Returns the keyspace and statement text.
43
0
  const std::string& keyspace() const { return keyspace_; }
44
110
  const std::string& text() const { return text_; }
45
46
  // Prepare the statement for execution. Optionally return prepared result if requested.
47
  CHECKED_STATUS Prepare(QLProcessor *processor, const MemTrackerPtr& mem_tracker = nullptr,
48
                         const bool internal = false, PreparedResult::UniPtr *result = nullptr);
49
50
  // Execute the prepared statement.
51
  CHECKED_STATUS ExecuteAsync(QLProcessor* processor, const StatementParameters& params,
52
                              StatementExecutedCallback cb) const;
53
54
  // Validate and return the parse tree.
55
  Result<const ParseTree&> GetParseTree() const;
56
57
  // Is this statement unprepared?
58
4.76M
  bool unprepared() const {
59
4.76M
    return !prepared_.load(std::memory_order_acquire);
60
4.76M
  }
61
62
  // Is this statement stale?
63
4.76M
  bool stale() const {
64
4.76M
    return parse_tree_->stale();
65
4.76M
  }
66
67
  // Clear the reparsed status.
68
4.76M
  void clear_reparsed() const {
69
4.76M
    parse_tree_->clear_reparsed();
70
4.76M
  }
71
72
 protected:
73
  // The keyspace this statement is parsed in.
74
  const std::string keyspace_;
75
76
  // The text of the SQL statement.
77
  const std::string text_;
78
79
 private:
80
  // The parse tree.
81
  ParseTree::UniPtr parse_tree_;
82
83
  // Mutex that protects the generation of the parse tree.
84
  std::mutex parse_tree_mutex_;
85
86
  // Atomic bool to indicate if the statement has been prepared.
87
  std::atomic<bool> prepared_ = {false};
88
};
89
90
}  // namespace ql
91
}  // namespace yb
92
93
#endif  // YB_YQL_CQL_QL_STATEMENT_H_