How to get Nth string after a pipe delimiter in hive - hive

I have some a table in Hive where in I want to extract 5th component of the string from one of the columns that looks like this -
Sample data
john:12|doe|google|usa|google.com|newspaper - title - 1 - volume - 1234|360671191
john:34|doe|fb|usa|google.com|newspaper - title - X - volume - 1233|360671192
john:45|doe|twitter|usa|google.com|newspaper - title - Y - volume - 1232|360671193
jane:45:1323
I would like to parse out 5th string after the first pipe character(|). The output column would have value as -
newspaper - title - 1 - volume - 1234
newspaper - title - X - volume - 1233
newspaper - title - Y - volume - 1232
jane:45:1323
In case the title is not present (like in record 4) , then we return the original string as is.

Use split function, like this:
with your_data as (
select stack(4,
'john:12|doe|google|usa|google.com|newspaper - title - 1 - volume - 1234|360671191',
'john:34|doe|fb|usa|google.com|newspaper - title - X - volume - 1233|360671192',
'john:45|doe|twitter|usa|google.com|newspaper - title - Y - volume - 1232|360671193',
'jane:45:1323'
) as str
)
select nvl(splitted_str[5], original_str) result
from
(
select split(str,'\\|') splitted_str, str original_str
from your_data
)s;
Returns:
newspaper - title - 1 - volume - 1234
newspaper - title - X - volume - 1233
newspaper - title - Y - volume - 1232
jane:45:1323

Related

Regular Expressions contains in bigquery example

I need to write regular expressions in bigquery to match the following two under title column: I want to get exactly these two. There are some other values containing 3 Percent, but I want to get only these two.
WBC - SAV - 3 Percent Q4 FY20
Canstar - canstar.com.au - AFF: Table Listing - Cost per click - National - 1x1 - 3 percent Savings
My code is:
WHEN REGEXP_CONTAINS(title, '(?i) 3 Percent')
THEN '3% PF'
I am not getting the correct output. Can anyone please assist.
There are some other values containing 3 Percent, but I want to get only these two.
So, in this case you don't need regular expression and rather use below
WHEN title IN (
'WBC - SAV - 3 Percent Q4 FY20',
'Canstar - canstar.com.au - AFF: Table Listing - Cost per click - National - 1x1 - 3 percent Savings'
) THEN '3% PF'

VB.NET How to get the last value from a Column in a DataTable

I have a DataTable called DTPerson like this:
Name - - - - - Age - - - - - Number
John - - - - - 16 - - - - - 1234567
Mike - - - - - 25 - - - - - 1231231
I need to retrieve the last field from the Column "Name" in DTPerson.
I want label1.text = Mike
I've looked everywhere and could only find examples for Datasets so I'm not sure what to do.
Try This.
DTPerson.Rows(DTPerson.Rows.Count -1).Item("Name").ToString()

How to do a MDX Except crossjoin dimension query

Consider the following data. I would like to get the NON{Country:USA & Gender:F} using MDX
- - - - - - - - - - - - - - - - - - - - -
| Country | Gender | Sales |
- - - - - - - - - - - - - - - - - - - - -
USA M 1000
USA F 500
Spain M 200
Spain F 600
What I want to extract would be:
- - - - - - - - - - - - - - - - - - - - -
| Country | Gender | Sales |
- - - - - - - - - - - - - - - - - - - - -
USA M 1000
Spain M 200
Spain F 600
I tried to use crossjoin, union and except to do that, e.g.
WITH SET [Test] AS
[Country].[CountryCode].[USA] * Except ([Gender].members,{[Gender].[GenderCode].[F]}) +
Except([Country].[CountryCode].members, {[Country].[CountryCode].[USA]}) * [Gender].members
SELECT
NON EMPTY [Test] ON ROWS,
{[Measures].[Sales]} ON COLUMNS
FROM [SalesCube]
It works, but may i know if there is any other simpler way to do it ?
Thanks.
If you want to exclude few combinations, you can use Except on the cross join with the excepted combinations as tuples like this:
WITH SET [Test] AS
Except(CrossJoin([Country].[CountryCode].members,
[Gender].members
),
{ ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) }
)
...
And syntactically, you an abbreviate CrossJoin as * and Except as -, as well as Union as +, which have the usual rules of precedence (* has higher precendece than - and +):
WITH SET [Test] AS
[Country].[CountryCode].members * [Gender].[GenderCode].members
-
{ ([Country].[CountryCode].[USA], [Gender].[GenderCode].[F]) }
...

How can I split a column based on similer values of column in SQL

I have a table in which 3 columns studentid, qualification and board.
It show like
Studentid - qualification - board
1 - highschool - cbse
1 - intermidiate - cbse
2 - highschool - up board
2 - intermidiate - up board
I need a query that give result like.
studentid - qualification-1 - qualification-2 - board-1 - board-2
1 - highschool - intermidiate - cbse - cbse
2 - highschool - intermidiate - up board - up board
Can any one solve it?
SELECT studentid, qualification AS 'qualification-1', qualification AS 'qualification-2', board AS 'board-1', board AS 'board-2' WHERE 1 GROUP BY studentid
Use AS to create alias of field

Replacing info in Access

I have a table within Access that looks similar to this:
ProductID - ClientID - ProductName - Description
118 - 5 - Full Search - xxxx
35 - 2 - Update - xxxx
105 - 7 - O & E - xxxx
I want to be able to call the ProductID and have it return the ProductName field.
ProductID = Forms!Orders.Product.Value()
Any help?
You can use DLookUp:
DlookUp("ProductName","Products","ProductID=" & SomeNumericID)
There are other ways, but you need to say where you are coming from and going to.