/Users/deen/code/yugabyte-db/src/yb/common/ql_datatype.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #include <glog/logging.h> |
15 | | |
16 | | #include "yb/common/ql_datatype.h" |
17 | | |
18 | | namespace yb { |
19 | | |
20 | 112 | DataType InternalToDataType(InternalType internal_type) { |
21 | 112 | switch (internal_type) { |
22 | 0 | case InternalType::kInt8Value: |
23 | 0 | return DataType::INT8; |
24 | 6 | case InternalType::kInt16Value: |
25 | 6 | return DataType::INT16; |
26 | 10 | case InternalType::kInt32Value: |
27 | 10 | return DataType::INT32; |
28 | 9 | case InternalType::kInt64Value: |
29 | 9 | return DataType::INT64; |
30 | 0 | case InternalType::kUint32Value: |
31 | 0 | return DataType::UINT32; |
32 | 0 | case InternalType::kUint64Value: |
33 | 0 | return DataType::UINT64; |
34 | 5 | case InternalType::kFloatValue: |
35 | 5 | return DataType::FLOAT; |
36 | 5 | case InternalType::kDoubleValue: |
37 | 5 | return DataType::DOUBLE; |
38 | 0 | case InternalType::kDecimalValue: |
39 | 0 | return DataType::DECIMAL; |
40 | 7 | case InternalType::kStringValue: |
41 | 7 | return DataType::STRING; |
42 | 6 | case InternalType::kTimestampValue: |
43 | 6 | return DataType::TIMESTAMP; |
44 | 13 | case InternalType::kDateValue: |
45 | 13 | return DataType::DATE; |
46 | 4 | case InternalType::kTimeValue: |
47 | 4 | return DataType::TIME; |
48 | 3 | case InternalType::kInetaddressValue: |
49 | 3 | return DataType::INET; |
50 | 1 | case InternalType::kJsonbValue: |
51 | 1 | return DataType::JSONB; |
52 | 3 | case InternalType::kUuidValue: |
53 | 3 | return DataType::UUID; |
54 | 35 | case InternalType::kTimeuuidValue: |
55 | 35 | return DataType::TIMEUUID; |
56 | 2 | case InternalType::kBoolValue: |
57 | 2 | return DataType::BOOL; |
58 | 3 | case InternalType::kBinaryValue: |
59 | 3 | return DataType::BINARY; |
60 | 0 | case InternalType::kMapValue: |
61 | 0 | return DataType::MAP; |
62 | 0 | case InternalType::kSetValue: |
63 | 0 | return DataType::SET; |
64 | 0 | case InternalType::kListValue: |
65 | 0 | return DataType::LIST; |
66 | 0 | case InternalType::kVarintValue: |
67 | 0 | return DataType::VARINT; |
68 | 0 | case InternalType::kFrozenValue: |
69 | 0 | return DataType::FROZEN; |
70 | 0 | case InternalType::kGinNullValue: // No such type in YCQL. |
71 | 0 | case InternalType::VALUE_NOT_SET: |
72 | 0 | case InternalType::kVirtualValue: |
73 | 0 | break; |
74 | 112 | } |
75 | 0 | LOG(FATAL) << "Internal error: unsupported type " << internal_type; |
76 | 0 | return DataType::NULL_VALUE_TYPE; |
77 | 112 | } |
78 | | |
79 | 8 | std::string InternalTypeToCQLString(InternalType internal_type) { |
80 | 8 | switch (internal_type) { |
81 | 8 | case InternalType::VALUE_NOT_SET: return "unknown"; |
82 | 0 | case InternalType::kInt8Value: return "tinyint"; |
83 | 0 | case InternalType::kInt16Value: return "smallint"; |
84 | 0 | case InternalType::kInt32Value: return "int"; |
85 | 0 | case InternalType::kInt64Value: return "bigint"; |
86 | 0 | case InternalType::kUint32Value: return "unknown"; // No such type in YCQL. |
87 | 0 | case InternalType::kUint64Value: return "unknown"; // No such type in YCQL. |
88 | 0 | case InternalType::kStringValue: return "text"; |
89 | 0 | case InternalType::kBoolValue: return "boolean"; |
90 | 0 | case InternalType::kFloatValue: return "float"; |
91 | 0 | case InternalType::kDoubleValue: return "double"; |
92 | 0 | case InternalType::kBinaryValue: return "blob"; |
93 | 0 | case InternalType::kTimestampValue: return "timestamp"; |
94 | 0 | case InternalType::kDecimalValue: return "decimal"; |
95 | 0 | case InternalType::kVarintValue: return "varint"; |
96 | 0 | case InternalType::kInetaddressValue: return "inet"; |
97 | 0 | case InternalType::kJsonbValue: return "jsonb"; |
98 | 0 | case InternalType::kListValue: return "list"; |
99 | 0 | case InternalType::kMapValue: return "map"; |
100 | 0 | case InternalType::kSetValue: return "set"; |
101 | 0 | case InternalType::kUuidValue: return "uuid"; |
102 | 0 | case InternalType::kTimeuuidValue: return "timeuuid"; |
103 | 0 | case InternalType::kDateValue: return "date"; |
104 | 0 | case InternalType::kTimeValue: return "time"; |
105 | 0 | case InternalType::kFrozenValue: return "frozen"; |
106 | 0 | case InternalType::kVirtualValue: return "virtual"; |
107 | 0 | case InternalType::kGinNullValue: return "unknown"; // No such type in YCQL. |
108 | 8 | } |
109 | 0 | LOG (FATAL) << "Invalid datatype: " << internal_type; |
110 | 0 | return "Undefined Type"; |
111 | 8 | } |
112 | | |
113 | | } // namespace yb |