You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/09 05:34:06 UTC
[GitHub] [shardingsphere] anonymous-lj commented on issue #17466: select union subquery NullPointerException
anonymous-lj commented on issue #17466:
URL: https://github.com/apache/shardingsphere/issues/17466#issuecomment-1120661171
@strongduanmu
config
`spring:
shardingsphere:
mode:
type: Memory
datasource:
names: fund
fund:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
rules:
sharding:
tables:
api_flow:
actual-data-nodes: fund.api_flow_${0..19}
table-strategy:
standard:
sharding-column: uuid
sharding-algorithm-name: custom-sharding
sharding-algorithms:
custom-sharding:
type: CLASS_BASED
props:
strategy: STANDARD
algorithmClassName: xxx.CustomSharding`
`public class CustomSharding implements StandardShardingAlgorithm<Comparable<?>> {
private final static SortedMap<Long, String> sortedMap = new TreeMap<>();
private static long getFNVHash(String str) {
final long p = 16777619;
long hash = 2166136261L;
long fnvSize = 4294967296L;
for (int i = 0; i < str.length(); i++) {
hash = ((hash ^ str.charAt(i)) * p) % fnvSize;
}
return hash;
}
static {
String tableName = "api_flow_";
for (int i = 0; i < 20; i++) {
String each = tableName + i;
sortedMap.put(getFNVHash(each), each);
for (int j = 0; j < 100; j++) {
sortedMap.put(getFNVHash(each + "_VN_" + j), each);
}
}
}
@Override
public void init() {
}
@Override
public String getType() {
return "custom-sharding";
}
@Override
public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Comparable<?>> shardingValue) {
long abs = getFNVHash(shardingValue.getValue().toString());
SortedMap<Long, String> subMap = sortedMap.tailMap(abs);
if (subMap.isEmpty()) {
long i = sortedMap.firstKey();
return sortedMap.get(i);
} else {
long i = subMap.firstKey();
return subMap.get(i);
}
}
@Override
public Collection<String> doSharding(Collection collection, RangeShardingValue rangeShardingValue) {
return null;
}
}
`
create table DDL
`CREATE TABLE `api_flow_x` (
`id` varchar(120) COLLATE utf8_bin NOT NULL,
`appid` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`uuid` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`operation_type` enum('deposit','withdrawal','rebate','transfer') COLLATE utf8_bin DEFAULT NULL,
`operation_mode` enum('telegraphic_withdrawal','system_withdrawal') COLLATE utf8_bin DEFAULT NULL,
`capital_flow` enum('outside_to_wallet','system_to_wallet','wallet_to_outside','mt4_to_wallet','mt4_to_mt4','wallet_to_wallet','wallet_to_mt4') COLLATE utf8_bin DEFAULT NULL,
`currency` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`original_balance` decimal(20,6) DEFAULT '0.000000',
`service_charge` decimal(20,6) DEFAULT '0.000000',
`original_service_charge` decimal(20,6) DEFAULT '0.000000',
`balance_change` decimal(20,6) DEFAULT '0.000000',
`existing_balance` decimal(20,6) DEFAULT '0.000000',
`order_serial` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`remark` text COLLATE utf8_bin,
`wallet_id` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`wallet_type` enum('commission','transaction') COLLATE utf8_bin DEFAULT 'transaction',
`create_time` datetime DEFAULT NULL,
`utype` varchar(120) COLLATE utf8_bin DEFAULT 'client',
`is_deleted` tinyint(1) DEFAULT '0',
`sync` tinyint(1) DEFAULT '0',
`micro_time` bigint(50) DEFAULT NULL,
`agents` text COLLATE utf8_bin,
`sales` text COLLATE utf8_bin,
`channel_code` varchar(120) COLLATE utf8_bin DEFAULT NULL,
`audit_rate` decimal(25,15) DEFAULT '0.000000000000000',
`usd_service_charge` decimal(20,6) DEFAULT '0.000000',
`usd_balance_change` decimal(20,6) DEFAULT '0.000000',
PRIMARY KEY (`id`),
KEY `index_operation_type` (`operation_type`) USING BTREE,
KEY `index_operation_mode` (`operation_mode`) USING BTREE,
KEY `index_capital_flow` (`capital_flow`) USING BTREE,
KEY `index_uuid` (`uuid`) USING BTREE,
KEY `index_appid` (`appid`) USING BTREE,
KEY `sync` (`sync`) USING BTREE,
KEY `agent` (`agents`(255)) USING BTREE,
KEY `sales` (`sales`(255)) USING BTREE,
KEY `currency` (`currency`) USING BTREE,
KEY `create_time_index` (`create_time`) USING BTREE,
KEY `wallet_id_uuid_index` (`wallet_id`,`uuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `api_fund_check_end` (
`wallet_id` varchar(120) NOT NULL,
`micro_time` bigint(11) NOT NULL,
`is_deleted` tinyint(1) NOT NULL,
`id` int(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org