当前位置:网站首页>array_ The contains() function uses
array_ The contains() function uses
2022-07-04 10:58:00 【ths512】
One 、array_contains function :
Hive Medium array_contains Function and SQL Medium in keyword The operation is similar to , Used to determine the inclusion (array_contains) Or does not contain (!array_contains) Relationship . And in The difference is array_contains It can be used to judge the same id Whether the same field in multiple records of contains one or more specified values . Pay attention to the consistency of field types , If inconsistent, you need to cast .
grammar :
array_contains( Array , value ), Returns a Boolean value .
Two ,array_contains() Function in where Case in condition
Solve the problem of using too many conditions in a field , The query condition is invalid
select *
from login
where dt='20130101'
and (ver !='3.1' or ver !='3.2'
or ver != '4.0'
or ver != '5.2');
select *
from login
where dt='20130101'
and (ver !='3.1' and ver !='3.2'
and ver != '4.0'
and ver != '5.2');
The purpose of this statement is to login from a user table , Inquire about 20130101 same day , The version is not 3.1,3.2,4.0,5.2 Login user record . however , stay hive0.90 perform , The last thing to come back is 20130101 All login user records of the day , The following query conditions seem to be ignored . Here, it seems that the same field does this kind of multiple != perhaps = The conditions of inquiry , Too much will fail .
So I modified the sentence , as follows :
select *
from login
where dt=20130101
and !array_contains(split('3.1,3.2,4.0,5.2',','),ver);
3、 ... and 、array_contians() Direct application cases :
Use array_contians() Label the monitoring indicators , Judge the alarm level .
select
task_id,
task_code,
task_version,
case
when array_contains(collect_set(tag_id), 599)
or array_contains(collect_set(tag_id), 1225)
then 'L1- Level '
when array_contains(collect_set(tag_id), 600)
or array_contains(collect_set(tag_id), 1226)
then 'L2- Level '
when array_contains(collect_set(tag_id), 601)
or array_contains(collect_set(tag_id), 1240)
then 'L3- Level '
when array_contains(collect_set(tag_id), 1166)
or array_contains(collect_set(tag_id), 1241)
then ' Eagle eye monitoring summary '
else ' Non eagle eye monitoring task '
end as core_tag_name
from
fdm.fdm_buffalo_uniontask_tag_theme_info_new
where
dt = sysdate( - 1)
group by
task_id,
task_code,
task_version
Four 、 Use array_contians() Tag users , In user portrait , Play a role in dimension construction
select
user_id,
count(*) as card_number -- Number of cards used
-- As long as any card is valid, it will be judged as VIP It works ,
case when array_contains(collect_set(status_code),cast(1 as smallint))
then 1
else 0
end AS effective_flag -- Card valid identification
from edw_users.dwd_edw_user_vipcard_df -- user VIP Use the full scale for card purchase
where dt = '${dt}'
and user_id > 0
and deleted_flag = 'N'
group by user_id
边栏推荐
- [test theory] test phase analysis (unit, integration, system test)
- 3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
- Canoe: the fourth simulation project -- bug debugging experience
- Introduction to Lichuang EDA
- [machine] [server] Taishan 200
- JMeter assembly point technology and logic controller
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Jemeter script recording
- Sword finger offer 05 (implemented in C language)
- Application and Optimization Practice of redis in vivo push platform
猜你喜欢
Canoe - description of common database attributes
[Galaxy Kirin V10] [server] set time synchronization of intranet server
Elevator dispatching (pairing project) ④
XMIND installation
Add t more space to your computer (no need to add hard disk)
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
Introduction to tree and binary tree
C language - stack
Network connection (III) functions and similarities and differences of hubs, switches and routers, routing tables and tables in switches, why do you need address translation and packet filtering?
JMeter common configuration components and parameterization
随机推荐
Ten key performance indicators of software applications
[Galaxy Kirin V10] [desktop] can't be started or the screen is black
Day06 list job
Interview and lecture summary 1
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
Quick sort (C language)
Advanced order of function
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
C language structure to realize simple address book
Summary of several job scheduling problems
Digital simulation beauty match preparation -matlab basic operation No. 6
3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
Postman interface test
Cacti主机模板之定制版
Elevator dispatching (pairing project) ①
[test theory] test process management
SSH原理和公钥认证
Regular expression
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download