extract data in hive - hive

I have data in a hive table column as below:
customer reason=Other#customer reason free text=Space#customer type=Regular#customer end date=2020-12-31 19:50:00#customer offering criterion=0#customer type=KK#Customer factor=0.00#customer period=0#customer type=TN#customer value=0#customer plan type=M#cttype type=KK#
I want to extract data value 0 against customer value.
I tried below query but it is giving full 'customer value=0' but i want only 0.
Please suggest.
select regexp_replace(regexp_extract(information,'customer period=[^#]*',0),'customer period=','') from detail;

The question is not clear at all.
If you want to limit the output, use LIMIT 1 (where 1 is number of rows you want to limit to)

Please give the following a shot,
---table creation----
create table ch7(custdetails map string,string>)
row format delimited
collection items terminated by '#'
map keys terminated by '=';
----data loading----
Load data local inpath 'your-file-location-in-local' overwrite into table ch7;
----data selection-----
select custdetails["customer value"] from ch7;
Hope this helps!!

Related

Regex comparison in Oracle between 2 varchar columns (from different tables)

I am trying to find a way to capture relevant errors from oracle alertlog. I have one table (ORA_BLACKLIST) with column values as below (these are the values which I want to ignore from
V$DIAG_ALERT_EXT)
Below are sample data in ORA_BLACKLIST table. This table can grow based on additional error to ignore from alertlog.
ORA-07445%[kkqctdrvJPPD
ORA-07445%[kxsPurgeCursor
ORA-01013%
ORA-27037%
ORA-01110
ORA-2154
V$DIAG_ALERT_EXT contains a MESSAGE_TEXT column which contains sample text like below.
ORA-01013: user requested cancel of current operation
ORA-07445: exception encountered: core dump [kxtogboh()+22] [SIGSEGV] [ADDR:0x87] [PC:0x12292A56]
ORA-07445: exception encountered: core dump [java_util_HashMap__get()] [SIGSEGV]
ORA-00600: internal error code arguments: [qercoRopRowsets:anumrows]
I want to write a query something like below to ignore the black listed errors and only capture relevant info like below.
select
dae.instance_id,
dae.container_name,
err_count,
dae.message_level
from
ORA_BLACKLIST ob,
V$DIAG_ALERT_EXT dae
where
group by .....;
Can someone suggest a way or sample code to achieve it?
I should have provided the exact contents of blacklist table. It currently contains some regex (perl) and I want to convert it to oracle like regex and compare with v$diag_alert_ext message_text column. Below are sample perl regex in my blacklist table.
ORA-0(,|$| )
ORA-48913
ORA-00060
ORA-609(,|$| )
ORA-65011
ORA-65020 ORA-31(,|$| )
ORA-7452 ORA-959(,|$| )
ORA-3136(,|)|$| )
ORA-07445.[kkqctdrvJPPD
ORA-07445.[kxsPurgeCursor –
Your blacklist table looks like like patterns, not regular expressions.
You can write a query like this:
select dae.* -- or whatever columns you want
from V$DIAG_ALERT_EXT dae
where not exists (select 1
from ORA_BLACKLIST ob
where dae.message_text like ob.<column name>
);
This will not have particularly good performance if the tables are large.

Hive and sql( any sql query)

I am posting question here related to hive dataware house?I have below sample data
Id,name,transctions
1,apple,(1,1,1,1)
2,mango,(1,1,1)
3,kiwi,(1,1,1)
...........
.......
In transctions column my data is array type. I am expecting below output.
Id,name,transtion
1,apple,4
2,mango,3
3,kiwi,3
I am guessing you want the size of the array:
select id, name, [size(transactions)][1]
from t;

APEX 5: How can I store the results of a MultiSelection from a List in an APEX-Item?

My example list:
How can I store the results in the Input Field "Your Choose" as comma-separate values (in this example: ALABAMA, ARIZONA).
Would APEX_UTIL.TABLE_TO_STRING be suitable?
You need to be more specific while asking questions.
I assume that you have page with
item PX_MULTISELECT.
process Before Header that loads data from DB to the input PX_MULTISELECT
And basing on this I assume you are asking how to get data separated with : from DB.
In process that loads data you should fetch data from db using listagg function
begin
select
listagg(COLUMN, ':') within group (order by 1)
into
:PX_MULTISELECT
from
...
where
...
end;
LISTAGG documentation

Logical operator sql query going weirdly wrong

I am trying to fetch results from my sqlite database by providing a date range.
I have been able to fetch results by providing 3 filters
1. Name (textfield1)
2. From (date)(textfield2)
3. To (date)(textfield3)
I am inserting these field values taken from form into a table temp using following code
Statement statement6 = db.createStatement("INSERT INTO Temp(date,amount_bill,narration) select date,amount,narration from Bills where name=\'"+TextField1.getText()+"\' AND substr(date,7)||substr(date,4,2)||substr(date,1,2) <= substr (\'"+TextField3.getText()+"\',7)||substr (\'"+TextField3.getText()+"\',4,2)||substr (\'"+TextField3.getText()+"\',1,2) AND substr(date,7)||substr(date,4,2)||substr(date,1,2) >= substr (\'"+TextField2.getText()+"\',7)||substr (\'"+TextField2.getText()+"\',4,2)||substr (\'"+TextField2.getText()+"\',1,2) ");
statement6.prepare();
statement6.execute();
statement6.close();
Now if i enter the following input in my form for the above filters
1.Ricky
2.01/02/2012
3.28/02/2012
It fetches date between these date ranges perfectly.
But now i want to insert values that are below and above these 2 date ranges provided.
I have tried using this code.But it doesnt show up any result.I simply cant figure where the error is
The below code is to find entries having date lesser than 01/02/2012 and greater than 28/02/2012.
Statement statementVII = db.createStatement("INSERT INTO Temp5(date,amount_rec,narration) select date,amount,narration from Bills where name=\'"+TextField1.getText()+"\' AND substr(date,7)||substr(date,4,2)||substr(date,1,2) < substr (\'"+TextField2.getText()+"\',7)||substr (\'"+TextField2.getText()+"\',4,2)||substr (\'"+TextField2.getText()+"\',1,2) AND substr(date,7)||substr(date,4,2)||substr(date,1,2) > substr (\'"+TextField3.getText()+"\',7)||substr (\'"+TextField3.getText()+"\',4,2)||substr (\'"+TextField3.getText()+"\',1,2)");
statementVII.prepare();
statementVII.execute();
statementVII.close();
Anyone sound on this,please guide.Thanks.
you need to use an Or clause together with brackets:
WHERE name='....' AND (yourDateField<yourLowerDate OR yourDateField>yourHigherDate)

Storing Select Query result in Variable Ruby on Rails

I wanted to know how we could store the result of my select query on a variable.
#ppt2 = Ppt.select('slide_name').where('id=?',4)
#ppt1 = Ppt.update_all({:time2=>#ppt2},['id like ?','1'])
Here, slide_name and time2 are both text attributes of the same table ppt.
What happens on the above execution is that the time2 field in id=1 gets the value "#ppt2" whereas I want it to get the value of slide_name from id=4 which does not get stored in #ppt1.
In other words, how do I store the value of the select query in #ppt2 so that it can be used in the next line?
Any help is appreciated.
Call the slide_name method on your first result.
#ppt2 = Ppt.select('slide_name').find(4).slide_name