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/exec/eval_misc.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
16
#include "yb/common/ql_value.h"
17
#include "yb/common/table_properties_constants.h"
18
#include "yb/common/typedefs.h"
19
20
#include "yb/yql/cql/ql/exec/exec_context.h"
21
#include "yb/yql/cql/ql/exec/executor.h"
22
23
#include "yb/yql/cql/ql/ptree/pt_dml.h"
24
#include "yb/yql/cql/ql/ptree/pt_expr.h"
25
#include "yb/yql/cql/ql/util/errcodes.h"
26
27
namespace yb {
28
namespace ql {
29
30
using std::shared_ptr;
31
32
//--------------------------------------------------------------------------------------------------
33
34
CHECKED_STATUS Executor::PTExprToPBValidated(const PTExprPtr& expr,
35
157
                                             QLExpressionPB *expr_pb) {
36
157
  RETURN_NOT_OK(PTExprToPB(expr, expr_pb));
37
150
  if (expr_pb->has_value() && IsNull(expr_pb->value())) {
38
2
    return exec_context_->Error(expr, "Value cannot be null.", ErrorCode::INVALID_ARGUMENTS);
39
2
  }
40
148
  return Status::OK();
41
148
}
42
43
1.29M
CHECKED_STATUS Executor::TimestampToPB(const PTDmlStmt *tnode, QLWriteRequestPB *req) {
44
1.29M
  if (tnode->user_timestamp_usec() != nullptr) {
45
66
    QLExpressionPB timestamp_pb;
46
66
    RETURN_NOT_OK(PTExprToPBValidated(tnode->user_timestamp_usec(), &timestamp_pb));
47
48
    // This should be ensured by checks before getting here.
49
0
    DCHECK(timestamp_pb.has_value() && timestamp_pb.value().has_int64_value())
50
0
        << "Integer constant expected for USING TIMESTAMP clause";
51
52
60
    UserTimeMicros user_timestamp = timestamp_pb.value().int64_value();
53
60
    if (user_timestamp == common::kInvalidUserTimestamp) {
54
2
      return exec_context_->Error(tnode->user_timestamp_usec(), "Invalid timestamp",
55
2
                                  ErrorCode::INVALID_ARGUMENTS);
56
2
    }
57
58
    req->set_user_timestamp_usec(timestamp_pb.value().int64_value());
58
58
  }
59
1.29M
  return Status::OK();
60
1.29M
}
61
62
1.29M
CHECKED_STATUS Executor::TtlToPB(const PTDmlStmt *tnode, QLWriteRequestPB *req) {
63
1.29M
  if (tnode->ttl_seconds() != nullptr) {
64
91
    QLExpressionPB ttl_pb;
65
91
    RETURN_NOT_OK(PTExprToPBValidated(tnode->ttl_seconds(), &ttl_pb));
66
67
    // this should be ensured by checks before getting here
68
0
    DCHECK(ttl_pb.has_value() && ttl_pb.value().has_int32_value())
69
0
        << "Integer constant expected for USING TTL clause";
70
71
88
    int32_t ttl_seconds = ttl_pb.value().int32_value();
72
73
88
    if (!yb::common::IsValidTTLSeconds(ttl_seconds)) {
74
2
      return exec_context_->Error(tnode->ttl_seconds(),
75
2
                                  strings::Substitute("Valid ttl range : [$0, $1]",
76
2
                                                      yb::common::kCassandraMinTtlSeconds,
77
2
                                                      yb::common::kCassandraMaxTtlSeconds).c_str(),
78
2
                                  ErrorCode::INVALID_ARGUMENTS);
79
2
    }
80
86
    req->set_ttl(static_cast<uint64_t>(ttl_seconds * MonoTime::kMillisecondsPerSecond));
81
86
  }
82
1.29M
  return Status::OK();
83
1.29M
}
84
85
}  // namespace ql
86
}  // namespace yb