当前位置:网站首页>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
边栏推荐
- Performance test process
- /*Write a loop to output the elements of the list container in reverse order*/
- Learning XML DOM -- a typical model for parsing XML documents
- TS type gymnastics: illustrating a complex advanced type
- Unittest+airtest+beatiulreport combine the three to make a beautiful test report
- SSH原理和公钥认证
- Sword finger offer 05 (implemented in C language)
- Knapsack problem and 0-1 knapsack problem
- JMeter assembly point technology and logic controller
- Postman interface test
猜你喜欢

The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer

VI text editor and user rights management, group management and time management

Canoe test: two ways to create CAPL test module

C language - stack
![[Galaxy Kirin V10] [server] KVM create Bridge](/img/a4/a35a276d13e194cefc547607c59f00.jpg)
[Galaxy Kirin V10] [server] KVM create Bridge
![[Galaxy Kirin V10] [server] iSCSI deployment](/img/60/13f43dc584c0768965d60811768948.jpg)
[Galaxy Kirin V10] [server] iSCSI deployment

Seven examples to understand the storage rules of shaped data on each bit

Canoe - the second simulation project -xvihicle1 bus database design (operation)

Huge number multiplication (C language)
![[Galaxy Kirin V10] [desktop] FTP common scene setup](/img/f6/e4fbfe69a6a7635ee6364114c46fd8.jpg)
[Galaxy Kirin V10] [desktop] FTP common scene setup
随机推荐
[Galaxy Kirin V10] [server] KVM create Bridge
Elevator dispatching (pairing project) ①
Article publishing experiment
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
Jemeter plug-in technology
C language - stack
3W word will help you master the C language as soon as you get started - the latest update is up to 5.22
Performance test overview
XMIND installation
For and while loops
/*Write a loop to output the elements of the list container in reverse order*/
TS type gymnastics: illustrating a complex advanced type
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
[Galaxy Kirin V10] [server] soft RAID configuration
[Galaxy Kirin V10] [desktop] cannot add printer
On binary tree (C language)
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?
Ten key performance indicators of software applications
Dictionaries and collections
/*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does