我正在开发一种同步机制,将数据从 aws redshift 移动到 aurora。为了降低网络 I/O 的负载,我正在转换 redshift 上的查询并向它们添加校验和查询,这样我将仅导出已更改的记录。我用另一个 Select * 查询包装基本查询并添加校验和函数。
我尝试删除一些内部子查询,之后新查询开始工作,但我无法更改查询,因为它是由其他一些平台提供的。
基本查询:
select x.player_id as playerid,
p.player_nickname,
r.region_code,
s.title as season_name,
x.rating as ranking_score,
x.rank_no as rank_no,
x.rank_no_change as rank_no_change,
x.game_mode,
to_char(ga.total_score, 'FM9D00') as gyo_perf_total_score,
to_char(agressive_score*100/aggresive_weight, 'FM9D000') as gyo_perf_aggressive_score,
to_char(defensive_score*100/defensive_weight, 'FM9D000') as gyo_perf_defensive_score,
to_char(survival_score*100/survival_weight, 'FM9D000') as gyo_perf_survival_score,
ga.match_place_avg,
rounds_played,
kills,
(kills*1.0)/rounds_played as avg_kills_per_round,
assists,
(assists*1.0)/rounds_played as avg_assists_per_round,
headshot_kills,
top10s,
(top10s*1.0)/rounds_played as top10s_ratio,
wins,
(wins*1.0)/rounds_played as win_ratio,
case when top10s = 0 then 0 else (wins*1.0)/(top10s*1.0) end as win_to_top10_ratio,
losses,
ga.match_group as ___matchgroup,
ga.last_update_id as ___lastupdateid_ga,
___lastupdateid_st,
x.last_update_id as ___lastupdateid_rn
from hd_stats.calc_player_ranking x
inner join hd_core.core_player p on x.player_id = p.player_id
and p.player_game_id =
(select g.game_id
from hd_core.core_game g
where lower(g.game_short_title) = 'xxxx')
left join hd_core.core_region r on x.region_id = r.region_id
left join hd_core.core_season s on x.season_id = s.season_id
--gyo perf
left join hd_stats.calc_pubg_gyo_average ga on
ga.player_id = x.player_id
and nvl(x.season_id,0) = nvl(ga.season_id,0)
and nvl(x.region_id,0) = nvl(ga.region_id,0)
and nvl(x.game_mode,'') = nvl(ga.match_mode,'')
left join (select player_id, region_id,
season_id, match_mode,
rounds_played as rounds_played,
kills as kills,
assists as assists,
headshot_kills as headshot_kills,
top10s as top10s,
wins as wins,
losses as losses,
lastupdate as ___lastupdateid_st
from hd_stats.calc_pubg_player_season_stats s
) as y
on x.player_id = y.player_id
and nvl(x.season_id,0) = nvl(y.season_id,0)
and nvl(x.region_id,0) = nvl(y.region_id,0)
and nvl(x.game_mode,'') = nvl(y.match_mode,'')
order by ___lastupdateid_rn
失败的转换查询:
Select top 100 *
,func_sha1(
''
)
as synch_checksum
from
(
select x.player_id as playerid,
p.player_nickname,
r.region_code,
s.title as season_name,
x.rating as ranking_score,
x.rank_no as rank_no,
x.rank_no_change as rank_no_change,
x.game_mode,
to_char(ga.total_score, 'FM9D00') as gyo_perf_total_score,
to_char(agressive_score*100/aggresive_weight, 'FM9D000') as gyo_perf_aggressive_score,
to_char(defensive_score*100/defensive_weight, 'FM9D000') as gyo_perf_defensive_score,
to_char(survival_score*100/survival_weight, 'FM9D000') as gyo_perf_survival_score,
ga.match_place_avg,
rounds_played,
kills,
(kills*1.0)/rounds_played as avg_kills_per_round,
assists,
(assists*1.0)/rounds_played as avg_assists_per_round,
headshot_kills,
top10s,
(top10s*1.0)/rounds_played as top10s_ratio,
wins,
(wins*1.0)/rounds_played as win_ratio,
case when top10s = 0 then 0 else (wins*1.0)/(top10s*1.0) end as win_to_top10_ratio,
losses,
ga.match_group as ___matchgroup,
ga.last_update_id as ___lastupdateid_ga,
___lastupdateid_st,
x.last_update_id as ___lastupdateid_rn
from hd_stats.calc_player_ranking x
inner join hd_core.core_player p on x.player_id = p.player_id
and p.player_game_id =
(select g.game_id
from hd_core.core_game g
where lower(g.game_short_title) = 'xxxx')
left join hd_core.core_region r on x.region_id = r.region_id
left join hd_core.core_season s on x.season_id = s.season_id
--gyo perf
left join hd_stats.calc_pubg_gyo_average ga on
ga.player_id = x.player_id
and nvl(x.season_id,0) = nvl(ga.season_id,0)
and nvl(x.region_id,0) = nvl(ga.region_id,0)
and nvl(x.game_mode,'') = nvl(ga.match_mode,'')
left join (select player_id, region_id,
season_id, match_mode,
rounds_played as rounds_played,
kills as kills,
assists as assists,
headshot_kills as headshot_kills,
top10s as top10s,
wins as wins,
losses as losses,
lastupdate as ___lastupdateid_st
from hd_stats.calc_pubg_player_season_stats s
) as y
on x.player_id = y.player_id
and nvl(x.season_id,0) = nvl(y.season_id,0)
and nvl(x.region_id,0) = nvl(y.region_id,0)
and nvl(x.game_mode,'') = nvl(y.match_mode,'')
order by ___lastupdateid_rn
)
有效的转换查询:
Select top 100 *
,func_sha1(
''
)
as synch_checksum
from
(
select x.player_id as playerid,
p.player_nickname,
r.region_code,
s.title as season_name,
x.rating as ranking_score,
x.rank_no as rank_no,
x.rank_no_change as rank_no_change,
x.game_mode,
to_char(ga.total_score, 'FM9D00') as gyo_perf_total_score,
to_char(agressive_score*100/aggresive_weight, 'FM9D000') as gyo_perf_aggressive_score,
to_char(defensive_score*100/defensive_weight, 'FM9D000') as gyo_perf_defensive_score,
to_char(survival_score*100/survival_weight, 'FM9D000') as gyo_perf_survival_score,
ga.match_place_avg,
rounds_played,
kills,
(kills*1.0)/rounds_played as avg_kills_per_round,
assists,
(assists*1.0)/rounds_played as avg_assists_per_round,
headshot_kills,
top10s,
(top10s*1.0)/rounds_played as top10s_ratio,
wins,
(wins*1.0)/rounds_played as win_ratio,
case when top10s = 0 then 0 else (wins*1.0)/(top10s*1.0) end as win_to_top10_ratio,
losses,
ga.match_group as ___matchgroup,
ga.last_update_id as ___lastupdateid_ga,
___lastupdateid_st,
x.last_update_id as ___lastupdateid_rn
from hd_stats.calc_player_ranking x
inner join hd_core.core_player p on x.player_id = p.player_id
and p.player_game_id = 2
--(select g.game_id
-- from hd_core.core_game g
-- where lower(g.game_short_title) = 'xxxx')
left join hd_core.core_region r on x.region_id = r.region_id
left join hd_core.core_season s on x.season_id = s.season_id
--gyo perf
left join hd_stats.calc_pubg_gyo_average ga on
ga.player_id = x.player_id
and nvl(x.season_id,0) = nvl(ga.season_id,0)
and nvl(x.region_id,0) = nvl(ga.region_id,0)
and nvl(x.game_mode,'') = nvl(ga.match_mode,'')
left join (select player_id, region_id,
season_id, match_mode,
rounds_played as rounds_played,
kills as kills,
assists as assists,
headshot_kills as headshot_kills,
top10s as top10s,
wins as wins,
losses as losses,
lastupdate as ___lastupdateid_st
from hd_stats.calc_pubg_player_season_stats s
) as y
on x.player_id = y.player_id
and nvl(x.season_id,0) = nvl(y.season_id,0)
and nvl(x.region_id,0) = nvl(y.region_id,0)
and nvl(x.game_mode,'') = nvl(y.match_mode,'')
order by ___lastupdateid_rn
)
期望获取基本查询上的所有记录和列以及校验和的另一列。
相反,我收到一个错误:
Amazon 无效操作:无法识别的节点类型:407; [SQL 状态=XX000,数据库错误代码=500310]
省略 ORDER BY 子句。这减轻了我的错误。
但是如果我想使用 order by 子句怎么办