Convert Numeric value to Binary value in hive - hive

I want to get a numeric value immediately after a particular word in string In hive
example : APDSGDSCRAM051 in that I need to get numeric value after word RAM is it possible in hive after that I need to convert the resulted value to binary
is it possible in hive ?
Note: its not a fixed length string

'create table string_testing (c string);
insert into table string_testing values ('APDSGDSCRAM051');
select substr(c, instr(c, 'RAM') + 3) from string_testing;
OK
051`

Related

What is a type of my value 675763582022462206:57 in sql creating data table query?

I am creating a table with several columns in sql:
CREATE TABLE.....
and one of them is going to have values like this: 675763582022462206:57. As you see it has : in it. So what is a type of it? Is it UInt16 or String?
It must be varchar or nvarchar in this case. The database doesn't recognize ":" as a part of a number, unless you say to Windows in advanced region settings that this is your decimal point. If you can store 57 (after ":") in a different column, then you can save the number before ":" as a bigint if you wish
This value can't be stored in a numeric type due to the colon (:), so you'll have to use one of the character types - i.e., a sufficiently long char or varchar.

Search with inequalities on string property

We are using NHibernate over SQL Server and SQLite.
The database stores records in rows rather than columns -- each row having Path|Value as columns. Path and Value are both string properties.
For certain values of Path we would like to query for inequalities -- greater-than, less-than, etc.
The trouble we are having is that because the properties are strings, the inequalities are using string comparisons -- for example, searching for Value >= 18 returns rows where Value = 5. Unfortunately we are having trouble working around this.
1) This restriction produces incorrect results (saying 18 < 5):
Restrictions.Ge("Value", item.Value);
2) We tried casting the value to an integer, but this code produces a SqlException from NHibernate -- Error converting data type nvarchar to bigint.
Restrictions.Le(Projections.Cast(NHibernateUtil.Int64, Projections.Property("SearchString")), item.Value)
3) We were looking for a way to pad the property value with zeros (so that we would get 018 > 005), but could not find a way to do this in NHibernate.
Does anyone have any advice?
Thank you in advance!
Assuming that you want to compare on integer value, with IQueryOver:
1) This restriction produces incorrect results (saying 18 < 5):
Restrictions.Ge("Value", item.Value);
Restrictions.Ge
(
Projections.Cast(NHibernateUtil.Int32, Projections.Property<YourEntity>(x => x.YourProperty))
, intValue
)
Convert your datatype accordingly. If your C# datatype (intValue) is already numeric, no need to convert it. If your x.YourProperty is already numeric type, no need to convert it. Adjust above code accordingly.
2) We tried casting the value to an integer, but this code produces a SqlException from NHibernate -- Error converting data type nvarchar to bigint.
Restrictions.Le(Projections.Cast(NHibernateUtil.Int64, Projections.Property("SearchString")), item.Value)
Refer the above and check the datatype of item.Value.

ERROR:22PO2 in PostgreSQL

SELECT COALESCE(REPLACE(substr(c.abc,strpos(c.abc,':')),':',''),'0') from book C
Here in the above query the column abc contains values as "21:34" / "text" which is in the character varying which has to be converted to BIGINT.
The above query is just converting small length of string but it's not converting bigger length of string.
I know that a regular expression can be used but unable to do implementation as I'm new to this.

QTP, How to convert a decimal value (VarType = 14) to any other VarType like int, etc

I'm running the following query in UFT to retrieve a value from the database. It returns the correct number for me. The number is 21572939 but the vartype for the number is vbDecimal(14).
sqlMsgQuery = ("SELECT MAX(CONTNO)FROM SERIES A, CONTRACT B WHERE A.SERIES = B.SERIES AND B.SERIES = "&"'AAA-W'"&_
"AND A.PARTY_ROLE IS NULL AND B.CONTNO BETWEEN 21573931 AND 21574930")
On the other hand, i have another variable that holds the same value but this value is being retrieve from an oracle application and the vartype is vbString(8)
my job is to verify if the the two numbers are equal and then write it to datatable. I've tried a lot but failed to convert a decimal value with a vartype(14) to int and compare it with the other string that i've converted to int already.
What i'm looking for:
1. Either a query that will convert the number into int in the database before it is sent to the variable so that i can use it as int
2. Or a vbscript function/code that will do the conversion.
3. Or any other solution.
Thanks in advance.
If the length of the SQL column CONTNO is 8, you need to create a variable with VBString(8) as data type for storing the result from the SQL query .
And modify the existing query like below.
sqlMsgQuery = ("SELECT CAST(MAX(CONTNO) as VARCHAR (8))
FROM SERIES A, CONTRACT B
WHERE A.SERIES = B.SERIES AND B.SERIES = "&"'AAA-W'"&_
"AND A.PARTY_ROLE IS NULL AND B.CONTNO BETWEEN 21573931 AND 21574930")
You can change the required data to the data type you want using CAST in SQL.
CAST ( expression AS data_type [ ( length ) ] )
When you get the column CAST it as (data_type you want) then compare. Make sure both are same DATA_TYPE and same LENGTH.

In Hive I need to Get numeric value after a particular word is it possible?

i want to get a numeric value immediately after a particular word in string
In hive for example :
APDSGDSCRAM051 in that i need to get numeric value after word RAM
is it possible in hive
Note: its not a fixed length string
Here you go, you need to use substr and instr pre-defined hive functions:
create table str_testing (c string);
insert into table str_testing values ('APDSGDSCRAM051');
select substr(c, instr(c, 'RAM') + 3) from str_testing;
OK
051
Time taken: 0.243 seconds, Fetched: 1 row(s)
As explained here, you can implemented in hive as
select regexp_extract(name, '\\d+', 0) from <table_name>;
Note: I do not have environment for Hive configured so you can check this by running at your end. Ya this will work only for first set of numbers found in your string, if you string has numbers at multiple places this might fail.