Get Column Data Type Using Active JDBC - activejdbc

How can I get column data types using Active JDBC ? Is It Possible?
I need data type for each column of my model for automation purposes.
Thanks in advance .

Yes, you can get that from a MetaModel:
MetaModel mm = person.getMetaModel();
Map<String, ColumnMetadata> cmMap = mm.getColumnMetadata();
ColumnMetadata cm = cmMap.get("first_name");
String typeName = cm.getTypeName();

Related

how to define a constant array and check if a value is in the array for Pig Latin

I want to define an array of user Ids in Pig and then filter data if the userId from the input is NOT in that array,
How do I do this in pig latin? Below is the example of what I intend to do
Thanks
inputData = load '$INPUT' USING PigStorage('|') AS (useriD:chararray,controllerAction:chararray,url:chararray,browserName:chararray,IsMobile:chararray,exceptionDetails:chararray,renderTime:int,serviceHostId:int,auditEventTime:chararray);
filteredInput = filter inputData by controllerAction is not null and auditEventTime is not null and serviceHostId is not null and renderTime is not null and useriD in ('2be2df06-f4ba-4d87-8938-09d867d3f2fe','ac1ac6bf-d151-49fc-8c7c-2b52d2efbb58','f00aec16-36e5-46ae-b7cb-a0f1eeefe609','258890f9-102a-4f8e-a001-ae24d2e25269','cf221779-a077-472c-b377-cca4a9230e1b');
Thanks Murali..I tried the approach of declaring a variable and then using Flatten and stringSplit to join..However I get the following error
Syntax error, unexpected symbol at or near 'flatteneduserids'
%declare REQUIRED_USER_IDS 'xxxxx,yyyyy,sssss' ;
inputData = load '$INPUT' USING PigStorage('|') AS (useriD:chararray,controllerAction:chararray,url:chararray,browserName:chararray,IsMobile:chararray,exceptionDetails:chararray,renderTime:int,serviceHostId:int,auditEventTime:chararray);
filteredInput = filter inputData by controllerAction is not null and auditEventTime is not null and serviceHostId is not null and renderTime is not null;
flatteneduserids = FLATTEN(STRSPLIT('$REQUIRED_USER_IDS',',')) AS (uid:chararray);
useridfilter = JOIN filteredInput BY useriD, flatteneduserids BY uid USING 'replicated';
so Now I tried another way of declaring flatteneduserids which results in the error Undefined alias: IN
flatteneduserids = FOREACH IN GENERATE FLATTEN(STRSPLIT('$REQUIREDUSERIDS',',')) AS (uid:chararray);
Had a similar use case. Tried the approach by declaring the constant value in %define and accessing the same inside IN clause, was not able to achieve the objective. (Refer : Declare a comma seperated string constant)
A thought worth contemplating ....
If the condition inside IN clause is a static/ reference/ meta kind of data, then would suggest to declare this in a static file. We can then read the data at run time and do an inner join with input data to retrieve the matching records.
input_data = LOAD '$INPUT' USING PigStorage('|') AS (user_id:chararray ...)
static_data = LOAD ... AS (req_user_id:chararray
required_data = JOIN input_data BY useriD, static_data BY req_user_id USING 'replicated';
required_data_fmt = -- project required fields.
I was not able to figure out how to do this in memory
So as per Murali's suggestion I added the user ids in a file..load the file and then do a join...that worked as expected for mr

QueryDSL like operation SimplePath

Similarly to this question I would like to perform an SQL "like" operation using my own user defined type called "AccountNumber".
The QueryDSL Entity class the field which defines the column looks like this:
public final SimplePath<com.myorg.types.AccountNumber> accountNumber;
I have tried the following code to achieve a "like" operation in SQL but get an error when the types are compared before the query is run:
final Path path=QBusinessEvent.businessEvent.accountNumber;
final Expression<AccountNumber> constant = Expressions.constant(AccountNumber.valueOfWithWildcard(pRegion.toString()));
final BooleanExpression booleanOperation = Expressions.booleanOperation(Ops.STARTS_WITH, path, constant);
expressionBuilder.and(booleanOperation);
The error is:
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [7!%%] did not match expected type [com.myorg.types.AccountNumber (n/a)]
Has anyone ever been able to achieve this using QueryDSL/JPA combination?
Did you try using a String constant instead?
Path<?> path = QBusinessEvent.businessEvent.accountNumber;
Expression<String> constant = Expressions.constant(pRegion.toString());
Predicate predicate = Expressions.predicate(Ops.STARTS_WITH, path, constant);
In the end, I was given a tip by my colleague to do the following:
if (pRegion != null) {
expressionBuilder.and(Expressions.booleanTemplate("{0} like concat({1}, '%')", qBusinessEvent.accountNumber, pRegion));
}
This seems to do the trick!
It seems like there is bug/ambiguity. In my case, I need to search by couple fields with different types (String, Number), e.g. SQL looks like:
SELECT * FROM table AS t WHERE t.name = "%some%" OR t.id = "%some%";
My code looks like:
BooleanBuilder where = _getDefaultPredicateBuilder();
BooleanBuilder whereLike = new BooleanBuilder();
for(String likeField: _likeFields){
whereLike = whereLike.or(_pathBuilder.getString(likeField).contains(likeValue));
}
where.and(whereLike);
If first _likeFields is type of String - request works fine, otherwise it throws Exception.

How to Update some data in a table from another table in MS Access 2007 by checking a value from the second one?

i want to update some data from a table (ehraz) in MS_Access 2007 by another table's data by checking this condition : if tableA.siba=Table2.siba then update Table1.field1 by Table2.Field2.
i use this t-sql command in sql server and works :
update ehraz set
ehraz.B_CODEMELI =bn.B_CodeMelli ,
ehraz.B_NAME =ltrim(rtrim(cast(bn.B_Name as nvarchar(20)))) ,
ehraz.B_FAMILY =ltrim(rtrim(cast (bn.B_Family as nvarchar(30)))) ,
ehraz.B_FATHER_N = ltrim(rtrim(cast(bn.B_Father_N as nvarchar(20)))),
ehraz.B_SHENAS =ltrim(rtrim(bn.B_Shenas)) ,
ehraz.B_TAVALOD = ltrim(rtrim(cast(bn.B_Tavalod as nvarchar(15)))),
ehraz.B_MOSHTARI = ltrim(rtrim(cast(bn.B_Moshtari as nvarchar(20)))) ,
ehraz.B_BARNO = ltrim(rtrim(cast(bn.B_Brno as nvarchar(10)))) ,
ehraz.CLOS = ltrim(rtrim(cast(bn.CLOS as nvarchar(5))))
from bn_data bn
where ehraz.siba = bn.Siba
how can i do this in MS-Access 2007? this query did't works in ms access.
Does this work for you?
update ehraz
inner join bn_data bn
on ehraz.siba = bn.Siba
set
ehraz.B_CODEMELI = bn.B_CodeMelli,
ehraz.B_NAME = Trim(CStr(bn.B_Name)),
ehraz.B_FAMILY = Trim(CStr(bn.B_Family)),
ehraz.B_FATHER_N = Trim(CStr(bn.B_Father_N)),
ehraz.B_SHENAS = Trim(CStr(bn.B_Shenas)),
ehraz.B_TAVALOD = Trim(CStr(bn.B_Tavalod)),
ehraz.B_MOSHTARI = Trim(CStr(bn.B_Moshtari)),
ehraz.B_BARNO = Trim(CStr(bn.B_Brno)),
ehraz.CLOS = Trim(CStr(bn.CLOS));
this query will not work in MS-Access because some of the keywords that are used in the query are not supported by MS-Access like the cast function is not supported in MS-Access. Instead Use CStr function for type conversion into text Format and CInt function to type conversion in Number format....
try replacing these keywords and let me know if this helps.

Convesion from Hive to PigLatin

I am trying to convert the below Hive statement to Pig:
max(substr(case when url like 'http:%' then '' else url end,1,50))
My pig statement for the above is:
url_group = GROUP data by (uid);
max_substr_url= FOREACH url_group generate SUBSTRING(MAX(((Coalesce(data.url) matches '.*http:%.*') ? '' : Coalesce(data.url))), 0, 49);
For some of the data, the url can be null. So I have written a pig UDF called Coalesce(String) which returns an empty string if the data is either null or empty. If the data is not null or not empty it returns the string back.
The above pig statement is giving me lot of trouble and tried n different options/ways but nothing worked. Anyone got any ideas on how to implement this? Please help me.
Thanks in advance
You are going to want to use a nested FOREACH so that you can do the substring transformation on each tuple in the data bag then take the MAX of the transformed bag.
A = GROUP data by (uid);
B = FOREACH url_group {
-- MAX needs a one column bag
transformed = FOREACH data
GENERATE SUBSTRING((Coalesce(url) matches '.*http:.*' ? '' : Coalesce(url)), 0, 49);
GENERATE group AS uid, MAX(transformed) ;
}

Lookup field and Invalid data has been used to update the list item error

I have list A with three columns JobNumber,Crew and Date which is lookup column to List B. When I create three individual lookup fields in List B then following code works fine,
SP.FieldLookupValue lvjobNum = new SP.FieldLookupValue();
lvjobNum.LookupId = ID;
lItem["JobNumber"] = lvjobNum;
SP.FieldLookupValue lvCrew = new SP.FieldLookupValue();
lvCrew.LookupId = ID;
lItem["Crew"] = lvCrew;
SP.FieldLookupValue lvDate = new SP.FieldLookupValue();
lvDate.LookupId = ID;
lItem["Date"] = lvDate;
However when I create lookup field using "Additional column settings" option like,
Then same code shown above doesn't work and it throws an error,
<nativehr>0x80070057</nativehr><nativestack></nativestack>Invalid data has been used to update the list item. The field you are trying to update may be read only.
Any idea ?
(Answered by the OP as an edit to the question. Transcribed here as a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
Fix was simple,
SP.FieldLookupValue flvRDS = new SP.FieldLookupValue();
flvRDS.LookupId = ID;
lItem["RDS"] = flvRDS;