|
15 | 15 | #include <ydb/library/yql/minikql/dom/json.h> |
16 | 16 | #include <ydb/library/yql/minikql/dom/yson.h> |
17 | 17 | #include <ydb/library/yql/public/udf/udf_types.h> |
| 18 | +#include <ydb/core/kqp/provider/yql_kikimr_expr_nodes.h> |
18 | 19 | #include <ydb/library/yql/utils/utf8.h> |
19 | 20 |
|
20 | 21 | namespace NKikimr { |
@@ -1167,7 +1168,141 @@ bool CheckValueData(NScheme::TTypeInfo type, const TCell& cell, TString& err) { |
1167 | 1168 | return ok; |
1168 | 1169 | } |
1169 | 1170 |
|
| 1171 | +bool CellFromLiteralExprNode(NYql::NNodes::TExprBase maybeLiteral, TCell& cell, TMemoryPool& valueDataPool) { |
| 1172 | + if (auto maybeJust = maybeLiteral.Maybe<NYql::NNodes::TCoJust>() ) { |
| 1173 | + maybeLiteral = maybeJust.Cast().Input(); |
| 1174 | + } |
| 1175 | + |
| 1176 | + if (maybeLiteral.Maybe<NYql::NNodes::TCoDataCtor>()) { |
| 1177 | + auto literal = maybeLiteral.Maybe<NYql::NNodes::TCoDataCtor>().Cast(); |
1170 | 1178 |
|
| 1179 | + auto type = literal.Ref().GetTypeAnn(); |
| 1180 | + auto slot = type->Cast<NYql::TDataExprType>()->GetSlot(); |
| 1181 | + auto value = literal.Literal().Value(); |
| 1182 | + |
| 1183 | + switch (slot) { |
| 1184 | + case NYql::NUdf::EDataSlot::Bool: { |
| 1185 | + ui8 v = FromString<bool>(value); |
| 1186 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1187 | + break; |
| 1188 | + } |
| 1189 | + case NYql::NUdf::EDataSlot::Uint8: { |
| 1190 | + ui8 v = FromString<ui8>(value); |
| 1191 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1192 | + break; |
| 1193 | + } |
| 1194 | + case NYql::NUdf::EDataSlot::Int8: { |
| 1195 | + i8 v = FromString<i8>(value); |
| 1196 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1197 | + break; |
| 1198 | + } |
| 1199 | + case NYql::NUdf::EDataSlot::Uint32: { |
| 1200 | + ui32 v = FromString<ui32>(value); |
| 1201 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1202 | + break; |
| 1203 | + } |
| 1204 | + case NYql::NUdf::EDataSlot::Int32: { |
| 1205 | + i32 v = FromString<i32>(value); |
| 1206 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1207 | + break; |
| 1208 | + } |
| 1209 | + case NYql::NUdf::EDataSlot::Uint64: { |
| 1210 | + ui64 v = FromString<ui64>(value); |
| 1211 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1212 | + break; |
| 1213 | + } |
| 1214 | + case NYql::NUdf::EDataSlot::Int64: { |
| 1215 | + i64 v = FromString<i64>(value); |
| 1216 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1217 | + break; |
| 1218 | + } |
| 1219 | + case NYql::NUdf::EDataSlot::Float: { |
| 1220 | + float v = FromString<float>(value); |
| 1221 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1222 | + break; |
| 1223 | + } |
| 1224 | + case NYql::NUdf::EDataSlot::Double: { |
| 1225 | + double v = FromString<double>(value); |
| 1226 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1227 | + break; |
| 1228 | + } |
| 1229 | + case NYql::NUdf::EDataSlot::Date: { |
| 1230 | + ui16 v = FromString<ui32>(value); |
| 1231 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1232 | + break; |
| 1233 | + } |
| 1234 | + case NYql::NUdf::EDataSlot::Datetime: { |
| 1235 | + ui32 v = FromString<ui32>(value); |
| 1236 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1237 | + break; |
| 1238 | + } |
| 1239 | + case NYql::NUdf::EDataSlot::Utf8: |
| 1240 | + case NYql::NUdf::EDataSlot::String: |
| 1241 | + case NYql::NUdf::EDataSlot::Yson: |
| 1242 | + case NYql::NUdf::EDataSlot::Json: { |
| 1243 | + cell = TCell(value.Data(), value.Size()); |
| 1244 | + break; |
| 1245 | + } |
| 1246 | + case NYql::NUdf::EDataSlot::Interval: { |
| 1247 | + i64 v = FromString<i64>(value); |
| 1248 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1249 | + break; |
| 1250 | + } |
| 1251 | + case NYql::NUdf::EDataSlot::Interval64: { |
| 1252 | + i64 v = FromString<i64>(value); |
| 1253 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1254 | + break; |
| 1255 | + } |
| 1256 | + case NYql::NUdf::EDataSlot::Timestamp: { |
| 1257 | + ui64 v = FromString<ui64>(value); |
| 1258 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1259 | + break; |
| 1260 | + } |
| 1261 | + case NYql::NUdf::EDataSlot::Timestamp64: { |
| 1262 | + i64 v = FromString<i64>(value); |
| 1263 | + cell = TCell((const char*)&v, sizeof(v)); |
| 1264 | + break; |
| 1265 | + } |
| 1266 | + case NYql::NUdf::EDataSlot::DyNumber: { |
| 1267 | + const auto dyNumber = NDyNumber::ParseDyNumberString(value); |
| 1268 | + if (!dyNumber.Defined()) { |
| 1269 | + return false; |
| 1270 | + } |
| 1271 | + const auto dyNumberInPool = valueDataPool.AppendString(TStringBuf(*dyNumber)); |
| 1272 | + cell = TCell(dyNumberInPool.data(), dyNumberInPool.size()); |
| 1273 | + } |
| 1274 | + case NYql::NUdf::EDataSlot::Decimal: { |
| 1275 | + const auto paramsDataType = type->Cast<NYql::TDataExprParamsType>(); |
| 1276 | + auto precision = FromString<ui8>(paramsDataType->GetParamOne()); |
| 1277 | + auto scale = FromString<ui8>(paramsDataType->GetParamTwo()); |
| 1278 | + |
| 1279 | + auto v = NYql::NDecimal::FromString(literal.Cast<NYql::NNodes::TCoDecimal>().Literal().Value(), precision, scale); |
| 1280 | + const auto p = reinterpret_cast<ui8*>(&v); |
| 1281 | + |
| 1282 | + std::pair<ui64,ui64>& valInPool = *valueDataPool.Allocate<std::pair<ui64,ui64>>(); |
| 1283 | + valInPool.first = *reinterpret_cast<ui64*>(p); |
| 1284 | + valInPool.second = *reinterpret_cast<ui64*>(p + 8); |
| 1285 | + cell = TCell((const char*)&valInPool, sizeof(valInPool)); |
| 1286 | + } |
| 1287 | + case NYql::NUdf::EDataSlot::Uuid: { |
| 1288 | + const ui64* uuidData = reinterpret_cast<const ui64*>(value.Data()); |
| 1289 | + |
| 1290 | + std::pair<ui64,ui64>& valInPool = *valueDataPool.Allocate<std::pair<ui64,ui64>>(); |
| 1291 | + valInPool.first = uuidData[0]; // low128 |
| 1292 | + valInPool.second = uuidData[1]; // high128 |
| 1293 | + cell = TCell((const char*)&valInPool, sizeof(valInPool)); |
| 1294 | + break; |
| 1295 | + } |
| 1296 | + default: |
| 1297 | + YQL_ENSURE(false, "Unexpected type slot " << slot); |
| 1298 | + } |
| 1299 | + |
| 1300 | + |
| 1301 | + return true; |
| 1302 | + } |
| 1303 | + |
| 1304 | + return false; |
| 1305 | +} |
1171 | 1306 |
|
1172 | 1307 | bool CellFromProtoVal(NScheme::TTypeInfo type, i32 typmod, const Ydb::Value* vp, |
1173 | 1308 | TCell& c, TString& err, TMemoryPool& valueDataPool) |
|
0 commit comments