CREATE TABLE `ods_active_role` ( `game_id` INT NOT NULL, `role_id` VARCHAR(64) NOT NULL, `ds` VARCHAR(64) NOT NULL, `user_account` varchar(64), `server_id` INT, `role_name` VARCHAR(50), `create_time` BIGINT) UNIQUE KEY (`game_id`, `role_id`,`ds`) DISTRIBUTED BY HASH ( `game_id`, `role_id`) BUCKETS 10

CREATE TABLE `ods_platform_order` (
  `game_id` INT NOT NULL,
 `order_id` varchar(100) NOT NULL,
  `game_name` varchar(30),
  `user_id` int,
  `user_account` varchar(50),
  `user_nickname` varchar(30),
  `role_id` varchar(50),
  `role_name` varchar(100),
  `server_id` varchar(50),
  `server_name` varchar(30),
  `platform_id` INT,
  `promote_id` INT,
  `amount` DECIMAL(10, 2),
  `status` tinyint NOT NULL,
  `pay_time` INT,
  `pay_way` tinyint,
  `pay_company` varchar(20),
  `ip` varchar(50),
  `is_box_pay` tinyint,
  `scene` tinyint,
  `prod_id` INT,
  `prod_name` varchar(30),
  `main_server_id` INT,
  `refund_type` tinyint

) UNIQUE KEY ( `game_id`,`order_id`) DISTRIBUTED BY HASH ( `game_id`,`order_id`) BUCKETS 32


CREATE TABLE `ods_platform_user` (
  `game_id` INT NOT NULL,
  `user_id` BIGINT NOT NULL,
  `user_account`  varchar(30),
  `platform_id` INT,
  `promote_id` INT,
  `create_time` BIGINT,
  `channel`  varchar(20)
)
  UNIQUE KEY (`game_id`, `user_id`)
DISTRIBUTED BY HASH  (`game_id`, `user_id`)  BUCKETS 32;


  CREATE TABLE `ods_role` (
    `game_id` INT NOT NULL COMMENT "游戏ID",
    `server_id` INT NOT NULL COMMENT "服务器ID",
    `role_id` VARCHAR(64) NOT NULL COMMENT "角色ID",
    `user_account` VARCHAR(64) COMMENT "用户账号",
    `role_name` VARCHAR(64) COMMENT "角色名称",
    `job` INT COMMENT "职业",
    `level` INT COMMENT "等级",
    `exp` BIGINT COMMENT "经验值",
    `relevel` INT COMMENT "转生等级",
    `platform_id` VARCHAR(64) COMMENT "平台ID",
    `create_time` DATETIME COMMENT "创建时间",  -- 修正：TIMESTAMP → DATETIME
    `ds` VARCHAR(64)  COMMENT "日期分区",              -- 优化：VARCHAR → DATE
    `main_server_id` INT COMMENT "主服ID"
)
ENGINE = OLAP  -- 必须显式指定表引擎[1,6](@ref)
UNIQUE KEY (`game_id`, `server_id`, `role_id`)

DISTRIBUTED BY HASH (`game_id`, `server_id`, `role_id`) BUCKETS 32
;

CREATE TABLE ods_role_duration (
    game_id INT NOT NULL,
    server_id INT NOT NULL,
    role_id  VARCHAR(64) NOT NULL,
    create_time DATETIME,
    user_account  VARCHAR(64),
    duration INT,
    level INT,
    role_name  VARCHAR(64)
) UNIQUE KEY (game_id, server_id, role_id, create_time)
DISTRIBUTED BY HASH (game_id, server_id, role_id, create_time) BUCKETS 32
;


CREATE TABLE ods_order (
    game_id int NOT NULL,
    order_id VARCHAR(64) NOT NULL,
    status int NOT NULL,
    user_account VARCHAR(64),
    role_id VARCHAR(64),
    server_id int,
    platform_id VARCHAR(64),
    product_id VARCHAR(64),
    amount bigint,
    create_time DATETIME,
    ds VARCHAR(64),
    receive_time DATETIME,
    pay_company VARCHAR(64),
    pay_type int

)
UNIQUE KEY (game_id, order_id, status)
DISTRIBUTED BY HASH (game_id, order_id, status) BUCKETS 32;

CREATE TABLE ods_server_user (
game_id int NOT NULL,
server_id int NOT NULL,
user_account VARCHAR(64) NOT NULL,
role_id VARCHAR(64),
role_name VARCHAR(64),

platform_id VARCHAR(64),
create_time DATETIME,
ds VARCHAR(64)
)
UNIQUE KEY (game_id, server_id, user_account) DISTRIBUTED BY HASH (game_id, server_id, user_account) BUCKETS 32;


CREATE TABLE ods_user (
game_id int NOT NULL,
user_account VARCHAR(64) NOT NULL,
role_id VARCHAR(64),
role_name VARCHAR(64),
server_id int,
platform_id VARCHAR(64),
create_time DATETIME,
ds VARCHAR(64)
)
UNIQUE KEY (game_id, user_account) DISTRIBUTED BY HASH (game_id, user_account) BUCKETS 32;




CREATE TABLE ods_platform_user (
game_id int NOT NULL,
user_id int NOT NULL,
user_account VARCHAR,
platform_id int,
promote_id int,
create_time bigint,
channel VARCHAR
)
UNIQUE KEY (game_id, user_id) DISTRIBUTED BY HASH (game_id, user_id) BUCKETS 32;


CREATE TABLE ods_platform_login (
game_id int NOT NULL,
user_id bigint NOT NULL,
user_account VARCHAR(100),
promote_id int,
platform_id int,
login_time int NOT NULL,
login_ip VARCHAR(50)
)  ENGINE = OLAP  DISTRIBUTED BY HASH (game_id, user_id) BUCKETS 32
;


CREATE TABLE juhe_user (
id bigint NOT NULL,
account VARCHAR,
register_time bigint,
register_ip VARCHAR,
external_id VARCHAR,
device_id VARCHAR,
game_id int,
game_name VARCHAR,
device VARCHAR,
channel_id VARCHAR,
package_id VARCHAR,
channel VARCHAR,
channel_uid VARCHAR
)
UNIQUE KEY (id) DISTRIBUTED BY HASH (id) BUCKETS 32;


CREATE TABLE juhe_order (
id bigint NOT NULL,
user_external_id VARCHAR,
game_identient VARCHAR,
game_name VARCHAR,
server_id VARCHAR,
server_name VARCHAR,
game_player_id VARCHAR,
game_player_name VARCHAR,
order_number VARCHAR,
game_order_number VARCHAR,
pay_order_number VARCHAR,
product_id VARCHAR,
props_name VARCHAR,
pay_amount DECIMAL(10,2),
create_time bigint,
pay_time bigint,
pay_status int,
pay_game_status int,
ip VARCHAR,
deviceinfo VARCHAR,
channel_id VARCHAR,
package_id VARCHAR,
channel VARCHAR
)
UNIQUE KEY (id) DISTRIBUTED BY HASH (id) BUCKETS 32;


CREATE TABLE game_server (
game_id int NOT NULL,
id int NOT NULL,
mid int,
name VARCHAR(50),
isconfirm tinyint,
del tinyint,
state tinyint,
open_time int,
space_id int,
space_type tinyint,
engine_version VARCHAR(255),
server_type VARCHAR(16),
kuafu_game_id VARCHAR(20)
)
UNIQUE KEY (game_id, id) DISTRIBUTED BY HASH (game_id, id) BUCKETS 32;


CREATE TABLE gm_space (
id int NOT NULL,
gm_uid int NOT NULL,
space_name VARCHAR(50),
space_type int,
buy_time int,
stime int,
etime int,
server_id int,
state tinyint
)
UNIQUE KEY (id) DISTRIBUTED BY HASH (id) BUCKETS 32;

CREATE TABLE ods_across_server (
id int NOT NULL,
game_id int NOT NULL,
serverids VARCHAR(100),
status tinyint,
create_time DATETIME NOT NULL
)
UNIQUE KEY (id) DISTRIBUTED BY HASH (id) BUCKETS 32;


CREATE TABLE cq_game_merge (
id bigint NOT NULL,
game_id int,
start_id int,
end_ids VARCHAR,
isconfirm int,
merge_time int
)
UNIQUE KEY (id) DISTRIBUTED BY HASH (id) BUCKETS 32;