当前位置:网站首页>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
边栏推荐
- Canoe - the second simulation project -xvihicle1 bus database design (operation)
- Introduction to canoe automatic test system
- 2022 ape circle recruitment project (software development)
- Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
- Software testing related resources
- Digital simulation beauty match preparation -matlab basic operation No. 6
- Snake (C language)
- How to use diff and patch to update the source code
- DNS hijacking
- Get the data of the top 100 headlines today with Tianxing data
猜你喜欢
[Galaxy Kirin V10] [server] soft RAID configuration
Ten key performance indicators of software applications
[Galaxy Kirin V10] [desktop] can't be started or the screen is black
How do microservices aggregate API documents? This wave of show~
Elevator dispatching (pairing project) ④
Canoe - the third simulation project - bus simulation-1 overview
Discussion | has large AI become autonomous? Lecun, chief scientist of openai
Canoe - the second simulation project -xvihicle1 bus database design (operation)
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
Add t more space to your computer (no need to add hard disk)
随机推荐
Day06 list job
1. Circular nesting and understanding of lists
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
Summary of several job scheduling problems
Recursive method to achieve full permutation (C language)
Application and Optimization Practice of redis in vivo push platform
Linked list operation can never change without its roots
On binary tree (C language)
Virtual machine configuration network
How do microservices aggregate API documents? This wave of show~
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
[Galaxy Kirin V10] [server] failed to start the network
Introduction to Lichuang EDA
DNS hijacking
Article publishing experiment
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Performance test method
Cacti主机模板之定制版
试题库管理系统–数据库设计[通俗易懂]