@@ -1306,13 +1306,13 @@ int ObAutoSplitArgBuilder::build_arg_(const uint64_t tenant_id,
1306
1306
arg.reset ();
1307
1307
ObTZMapWrap tz_map_wrap;
1308
1308
share::schema::AlterTableSchema& alter_table_schema = arg.alter_table_schema_ ;
1309
-
1310
1309
if (tenant_id == OB_INVALID_ID) {
1311
1310
ret = OB_ERR_UNEXPECTED;
1312
1311
LOG_WARN (" invalid tenant_id" , KR (ret), K (tenant_id));
1313
1312
} else if (OB_FAIL (build_alter_table_schema_ (tenant_id, db_name, table_schema,
1314
1313
split_source_tablet_id,
1315
1314
ranges,
1315
+ arg.tz_info_wrap_ .get_time_zone_info (),
1316
1316
alter_table_schema))) {
1317
1317
LOG_WARN (" fail to build alter_table_schema" , KR (ret), K (tenant_id), K (db_name),
1318
1318
K (table_schema), K (split_source_tablet_id),
@@ -1334,7 +1334,6 @@ int ObAutoSplitArgBuilder::build_arg_(const uint64_t tenant_id,
1334
1334
LOG_WARN (" failed to build ddl stmt str" , K (ret), K (tenant_id), K (table_schema.get_table_id ()), K (split_source_tablet_id));
1335
1335
}
1336
1336
}
1337
-
1338
1337
return ret;
1339
1338
}
1340
1339
@@ -1517,6 +1516,7 @@ int ObAutoSplitArgBuilder::build_alter_table_schema_(const uint64_t tenant_id,
1517
1516
const share::schema::ObTableSchema &table_schema,
1518
1517
const ObTabletID split_source_tablet_id,
1519
1518
const ObArray<ObNewRange> &ranges,
1519
+ const ObTimeZoneInfo *tz_info,
1520
1520
share::schema::AlterTableSchema &alter_table_schema)
1521
1521
{
1522
1522
int ret = OB_SUCCESS;
@@ -1548,7 +1548,7 @@ int ObAutoSplitArgBuilder::build_alter_table_schema_(const uint64_t tenant_id,
1548
1548
const ObRowkey& high_bound_val = ranges[i].get_end_key ();
1549
1549
1550
1550
if (OB_FAIL (build_partition_ (tenant_id, table_id,
1551
- split_source_tablet_id, high_bound_val,
1551
+ split_source_tablet_id, high_bound_val, tz_info,
1552
1552
new_part))) {
1553
1553
LOG_WARN (" fail to build partition" , KR (ret), K (tenant_id), K (table_id), K (split_source_tablet_id),
1554
1554
K (high_bound_val), K (table_schema));
@@ -1559,6 +1559,7 @@ int ObAutoSplitArgBuilder::build_alter_table_schema_(const uint64_t tenant_id,
1559
1559
}
1560
1560
}
1561
1561
1562
+
1562
1563
if (OB_FAIL (ret)) {
1563
1564
} else if (OB_FAIL (rootserver::ObDDLService::fill_part_name (table_schema, alter_table_schema))) {
1564
1565
LOG_WARN (" failed to fill part name" , K (ret));
@@ -1588,11 +1589,18 @@ int ObAutoSplitArgBuilder::build_alter_table_schema_(const uint64_t tenant_id,
1588
1589
int ObAutoSplitArgBuilder::build_partition_ (const uint64_t tenant_id, const uint64_t table_id,
1589
1590
const ObTabletID split_source_tablet_id,
1590
1591
const ObRowkey &high_bound_val,
1592
+ const ObTimeZoneInfo *tz_info,
1591
1593
share::schema::ObPartition &new_part)
1592
1594
{
1593
1595
int ret = OB_SUCCESS;
1594
-
1595
- if (OB_FAIL (new_part.set_high_bound_val (high_bound_val))) {
1596
+ bool need_cast = false ;
1597
+ ObRowkey cast_high_bound_val;
1598
+ common::ObArenaAllocator cast_allocator;
1599
+ if (OB_FAIL (check_and_cast_high_bound (high_bound_val, tz_info, cast_high_bound_val, need_cast, cast_allocator))) {
1600
+ LOG_WARN (" failed to check cast high bound" , K (ret));
1601
+ } else if (need_cast && OB_FAIL (new_part.set_high_bound_val (cast_high_bound_val))) {
1602
+ LOG_WARN (" failed to set high_bound_val" , KR (ret));
1603
+ } else if (!need_cast && OB_FAIL (new_part.set_high_bound_val (high_bound_val))) {
1596
1604
LOG_WARN (" failed to set high_bound_val" , KR (ret));
1597
1605
} else {
1598
1606
new_part.set_is_empty_partition_name (true );
@@ -1602,6 +1610,79 @@ int ObAutoSplitArgBuilder::build_partition_(const uint64_t tenant_id, const uint
1602
1610
new_part.set_partition_type (PartitionType::PARTITION_TYPE_NORMAL);
1603
1611
}
1604
1612
1613
+ if (OB_NOT_NULL (cast_high_bound_val.get_obj_ptr ())) {
1614
+ cast_high_bound_val.destroy (cast_allocator);
1615
+ }
1616
+ return ret;
1617
+ }
1618
+
1619
+ int ObAutoSplitArgBuilder::check_and_cast_high_bound (const ObRowkey &origin_high_bound_val,
1620
+ const ObTimeZoneInfo *tz_info,
1621
+ ObRowkey &cast_hight_bound_val,
1622
+ bool &need_cast,
1623
+ ObIAllocator &allocator)
1624
+ {
1625
+ int ret = OB_SUCCESS;
1626
+ const ObObj *ori_obj_ptr = origin_high_bound_val.get_obj_ptr ();
1627
+ const int64_t obj_count = origin_high_bound_val.get_obj_cnt ();
1628
+ need_cast = false ;
1629
+ cast_hight_bound_val.reset ();
1630
+ if (OB_ISNULL (ori_obj_ptr)) {
1631
+ ret = OB_ERR_UNEXPECTED;
1632
+ LOG_WARN (" object ptr should not be null" , K (ret), K (origin_high_bound_val));
1633
+ } else {
1634
+ for (int64_t i = 0 ; OB_SUCC (ret) && !need_cast && i < obj_count; ++i) {
1635
+ if (OB_FAIL (check_need_to_cast (ori_obj_ptr[i], need_cast))) {
1636
+ LOG_WARN (" fail to check need to cast" , K (ret), K (ori_obj_ptr[i]));
1637
+ }
1638
+ }
1639
+ if (OB_SUCC (ret) && need_cast) {
1640
+ ObObj *cast_obj_ptr = nullptr ;
1641
+ if (OB_FAIL (origin_high_bound_val.deep_copy (cast_hight_bound_val, allocator))) {
1642
+ LOG_WARN (" failed to copy rowkey" , K (origin_high_bound_val));
1643
+ } else if (OB_ISNULL (cast_obj_ptr = cast_hight_bound_val.get_obj_ptr ())) {
1644
+ ret = OB_ERR_UNEXPECTED;
1645
+ LOG_WARN (" object ptr should not be null" , K (ret), K (cast_obj_ptr));
1646
+ } else {
1647
+ for (int64_t i = 0 ; OB_SUCC (ret) && i < obj_count; ++i) {
1648
+ const ObObj *o_obj_ptr = &ori_obj_ptr[i];
1649
+ ObObj *c_obj_ptr = &cast_obj_ptr[i];
1650
+ bool need_to_cast = false ;
1651
+ if (OB_ISNULL (c_obj_ptr) || OB_ISNULL (o_obj_ptr)) {
1652
+ ret = OB_ERR_UNEXPECTED;
1653
+ LOG_WARN (" ptr should not be null" , K (ret), K (c_obj_ptr), K (o_obj_ptr));
1654
+ } else if (OB_FAIL (check_need_to_cast (*o_obj_ptr, need_to_cast))) {
1655
+ LOG_WARN (" fail to check need to cast" , K (ret), K (*o_obj_ptr));
1656
+ } else if (need_to_cast) {
1657
+ const ObObjType expected_obj_type = ori_obj_ptr[i].is_timestamp_ltz () ? ObTimestampTZType : (ob_is_int_tc (c_obj_ptr->get_type ()) ? ObIntType : ObUInt64Type);
1658
+ int64_t cm_mode = CM_NONE;
1659
+ ObDataTypeCastParams dtc_params;
1660
+ dtc_params.tz_info_ = tz_info;
1661
+ ObCastCtx cast_ctx (&allocator, &dtc_params, cm_mode, c_obj_ptr->get_meta ().get_collation_type ());
1662
+ if (OB_FAIL (ObObjCaster::to_type (expected_obj_type, cast_ctx, *o_obj_ptr, *c_obj_ptr))) {
1663
+ STORAGE_LOG (WARN, " fail to cast obj" ,
1664
+ K (ret), K (*o_obj_ptr), K (*c_obj_ptr), K (o_obj_ptr->get_type ()),
1665
+ K (ob_obj_type_str (o_obj_ptr->get_type ())),
1666
+ K (o_obj_ptr->get_meta ().get_type ()), K (ob_obj_type_str (o_obj_ptr->get_meta ().get_type ())));
1667
+ }
1668
+ }
1669
+ }
1670
+ }
1671
+ }
1672
+ }
1673
+ return ret;
1674
+ }
1675
+
1676
+ int ObAutoSplitArgBuilder::check_need_to_cast (const ObObj &obj, bool &need_to_cast)
1677
+ {
1678
+ int ret = OB_SUCCESS;
1679
+ if (OB_UNLIKELY (!obj.is_valid_type ())) {
1680
+ ret = OB_INVALID_ARGUMENT;
1681
+ LOG_WARN (" invalid type" , K (ret), K (obj));
1682
+ } else {
1683
+ need_to_cast = (ob_is_integer_type (obj.get_type ()) && (ObIntType != obj.get_type () || ObUInt64Type != obj.get_type ()))
1684
+ || obj.is_timestamp_ltz ();
1685
+ }
1605
1686
return ret;
1606
1687
}
1607
1688
0 commit comments