where with multiple column and anyof() with dexie - dexie

I have table data as mentioned below.
Id Name Type
1 ABC SCAN
2 BDC SCAN
3 ABC MANUAL
4 BDC EXTDEV
5 ABC EXTDEV
As per the above Tbl data want ABC data including all 3 types.
I have tried below function
export const getInventoryScanProductByAccNameAndType = async (
accName
) => await db.InventoryScans
.where(['AccountName', 'ProductEnterType']).anyOf(accName, ['SCAN', 'MANUAL', 'EXTDEVICE']).toArray();
Can anyone help me to get the data below?
Id Name Type
1 ABC SCAN
2 ABC MANUAL
3 ABC EXTDEV

Related

LATERAL VIEW explode funtion in hive

I am trying to export data from excel into a hive table, while doing so, i have a column 'ABC' which has values like '1,2,3'.
I used the lateral view explode function but it does not does anything to my data.
Following is my code snippet :
CREATE TABLE table_name
(
id string,
brand string,
data_name string,
name string,
address string,
country string,
flag string,
sample_list array )
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
;
LOAD DATA LOCAL INPATH 'location' INTO TABLE
table_name ;
output sample:
id brand data_name name address country flag sample_list
19 1 ABC SQL ABC Cornstarch IN 1 ["[1,2,3]"]
then i do:
select * from franchise_unsupress LATERAL VIEW explode(SEslist) SEslist as final_SE;
output sample:
id brand data_name name address country flag sample_list
19 1 ABC SQL ABC Cornstarch IN 1 [1,2,3]
I also tried:
select * from franchise_unsupress lateral view explode(split(SEslist,',')) SEslist AS final_SE ;
but got an error:
FAILED: ClassCastException org.apache.hadoop.hive.serde2.objectinspector.StandardListObjectInspector cannot be cast to org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector
whereas, what i need is:
id brand data_name name address country flag sample_list
19 1 ABC SQL ABC Cornstarch IN 1 1
19 1 ABC SQL ABC Cornstarch IN 1 2
19 1 ABC SQL ABC Cornstarch IN 1 3
Any help will be greatly appreciated! thank you
The problem is that array is recognized in a wrong way and loaded as a single element array ["[1,2,3]"]. It should be [1,2,3] or ["1","2","3"] (if it is array<string>)
When creating table, specify delimiter for collections:
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
I wanted to provide my answer.
The issue was with the input that was being provided. My input txt file had [] around the input value. They had to be removed and it worked.

PIG: Filter hive table by previous table result

I need to query one HIVE table and filter the other table with one column of the previous one.
Example:
A = LOAD 'db.table1' USING org.apache.hive.hcatalog.pig.HCatLoader();
filterA = filter A by (id=='123');
B = LOAD 'db.table2' USING org.apache.hive.hcatalog.pig.HCatLoader();
//the problem is here. filterA has many rows. I need to apply filter for each of the row.
filterB = filter B by (id==filterA.id);
Data in A:
tabid id dept location
1 1 IS SJ
2 4 CS SF
3 5 EC MD
Data in B:
tabid id name address
1 4 john 123 S AVE
2 5 jane 456 N BLVD
3 9 nick 789 GREAT LAKE DR
Expected Result:
tabid id name address
1 4 john 123 S AVE
2 5 jane 456 N BLVD
As asked in the comment, it sounds like what you're looking for is a join. Sorry if I misunderstood your question.
A = LOAD 'db.table1' USING org.apache.hive.hcatalog.pig.HCatLoader();
B = LOAD 'db.table2' USING org.apache.hive.hcatalog.pig.HCatLoader();
C = JOIN A by id, B by id;

linq query to fetch data by employee wise

emp_master:
empid,empname
I am having one table called as
employee_travel
travelid empid location date
1 101 abc 3/4/2014
2 102 lmn 4/4/2014
3 101 abc 5/4/2014
4 102 lmn 6/4/2014
5 101 xyz 7/4/2014
6 102 cdf 8/4/2014
now iIwant to display records employee wise like:
empid location date
101 abc --
101 abc --
101 xyz
102 lmn
102 lmn
102 cdf
I have written following query in linq:
var data = (from r in context.employee_travel
group r by new
{
r.Emp_id
} into g
select new
{
name = r.emp_master.empname,
r.date,
r.location
})
But it is giving me error on this line:
****name = r.emp_master.empname,
r.date
r.location****
Here{name is used as anonomous type in query are name of d**atatextfield of my gridview**.}
Can anyone edit my linq query to suit my needs ????
Please please please help me. I am very much new to linq so I don't know how to write this query.
from et in employee_travel
orderby et.empid
select new
{
Employee = et.Employee,
TravelRecord = et, //if you want objects
Name = et.Employee.Name,
Date = et.Date //if you want simple types
}
In that sample I chose to return the entity, but you can of course return names, dates, etc. And you can add more ordering if you need.
Or you can just get the employee_travel entity and include the employee (make sure you have the right include property name)
db.employee_travel.Include("employee").OrderBy(et=>et.empid).ToList()

wrong result possibly because MergeAs(AppendOnly) LINQ

NOTE
This might be a dup of this. But I don't get a clear answer from that.
The problem
I got wrong result from linq.
EXAMPLE
id groupid status name
------------------------------------
guid1 guidA reserved truck1
guid2 guidA reserved truck2
guid3 guidA reserved truck3
guid4 guidA reserved truck4
*assume all guids are guids..
**id is a primary key (unique)
CASE
If I put only where groupid == guidA the result is correct (4 rows)
but, if I put where groupid == guidA && status == reserved the result is wrong (3 rows)
EXPLANATION
The query built with expression tree. From the debug watch, the query (that return wrong the result) is like this
query.Expression:
-----------------
Convert(value(System.Data.Objects.ObjectSet`1[myEFTable]))
.MergeAs(AppendOnly)
.Where(m => ( m.groupId == value(myFilterClass).groupId))
.Where(m => m.status.Contains(value(myFilterClass).statusStr))
.Select(m => new myViewClass()
{
Id = m.id, GroupId = m.groupid, Status = m.status, Name = m.name
})
.OrderBy(o => o.Name).Skip(0).Take(10)
Then I tried to run a similar query and it returns correct result
assume e is ObjectSet<myEFTable> and strGuid is guidA
Guid grId = new Guid(strGuid);
e.AsQueryable()
.Where(m => m.status.Contains("reserved"))
.Where(m => m.groupId == grId)
.Select(m => new myViewClass()
{
Id = m.id, GroupId = m.groupid, Status = m.status, Name = m.name
}).OrderBy(o => o.Name).Skip(0).Take(10);
QUESTION
I'm completely clueless about this error..
If my EF tables are correct and the query is correct, why does it return wrong result?
Is it because the MergeAs(AppendOnly) ? because the only thing that different is that.
If this is about unique key, what should I do with myViewClass to ensure that every row is unique and should not be merged (if that was the case) ?
---------------------------------------------------------------------
UPDATE 2013/08/29
The result is incorrect because I have a typos in one of my query..
So, after changing few lot of here and there, try and error, till I almost lost the trace of whatever that changed, commented, erased, suddenly it works.. EUREKA!! what?
what I did is not really change everything, it's just a lot of changes but doesn't really end up so much different than where I was starting.. so there's that!
then that EUREKA moment ends and leave me tracing my way back to find out what is actually wrong, simply because I don't believe in miracles..
so here it is..
The tables is actually similar to this:
PartsGroups
-----------
id name
-----------
1 Nails
-----------
Items
-----------------
id name status
-----------------
2 Table Empty
5 Table Indent
6 Door Empty
3 Sofa Empty
PartsGroupPairs
------------------
id groupId partId
------------------
1 1 4
2 1 7
3 1 8
4 1 15
-------------------
Parts
------------------------
id name itemId status
------------------------
4 XNail 2 Empty
7 SNail 5 Empty
8 UNail 6 Empty
15 ZNail 3 Empty
------------------------
The relationships is like this
PartsGroups PartsGroupPairs Parts Items
----------- ------------------ ------------------------ -----------------
id name id groupId partId id name itemId status id name status
----------- ------------------ ------------------------ -----------------
1 Nails 1 1 4 4 XNail 2 Empty 2 Table Empty
1 Nails 2 1 7 7 SNail 5 Empty 5 Table Indent
1 Nails 3 1 8 8 UNail 6 Empty 6 Door Empty
1 Nails 4 1 15 15 ZNail 3 Empty 3 Sofa Empty
----------- ------------------- ------------------------ -----------------
One <---> Many Many <---> One Many <------> One
PartsGroup.pairs is a collection of PartsGroupPairs
PartsGroupPair.group is a PartsGroup
PartsGroupPair.part is a Part
Part.item is an Item
Item.parts is a collection of Parts
So when I select PartsGroup where name == 'Nails' it works perfectly, it returns 4 rows
But why when I select PartsGroup where name == 'Nails' and Status == 'Empty' it returns 3 rows?? (see below)
PartsGroups PartsGroupPairs Parts Items
----------- ------------------ ------------------------ -----------------
id name id groupId partId id name itemId status id name status
----------- ------------------ ------------------------ -----------------
1 Nails 1 1 4 4 XNail 2 Empty 2 Table Empty
1 Nails 3 1 8 8 UNail 6 Empty 6 Door Empty
1 Nails 4 1 15 15 ZNail 3 Empty 3 Sofa Empty
----------- ------------------- ------------------------ -----------------
this row didnt get selected..
PartsGroups PartsGroupPairs Parts Items
----------- ------------------ ------------------------ -----------------
id name id groupId partId id name itemId status id name status
----------- ------------------ ------------------------ -----------------
1 Nails 2 1 7 7 SNail 5 Empty 5 Table Indent
----------- ------------------- ------------------------ -----------------
the mistake I made is at the Where part. The query itself built at the runtime coz I separate entities, filters, views and paging modules. So mostly I just passing IQueryable here and there.
In the case for filter, every time I filter, I'll add another Where. So in this case it went like this below:
using(var DB = new databaseContext())
{
ObjectSet<PartsGroupPair> d =
DB.CreateObjectSet<PartsGroupPair>("partsGroupPair");
int searchGroupId = 1; // int instead of guid for example
int searchStatus = "Empty";
// filter by specific PartsGroup
IQueryable<PartsGroupPair> e = d.Where(m => m.group.id == searchGroupId);
// then if I want to filter by the status
e = e.Where(m => m.part.item.status == searchStatus)); // WRONG!!
// I want to filter by part.status, not item.status
// so instead, it should be
e = e.Where(m => m.part.status == searchStatus)); // RIGHT!!
// view
IQueryable<PartsGroupPairView> f =
e.Select(m => new PartsGroupPairView()
{
Id = m.id, GroupId = m.groupid,
Status = m.part.status, Name = m.part.name
// etc..
});
// paging
f = f.OrderBy(o => o.Name).Skip(0).Take(10);
}
The wrong filtering makes LINQ ignore the other Parts, and returns 3 rows instead of 4 because it found only one Item instead of 2 Parts.
So in my case, it's a silly typo with a quite complex data..
It's really frustrating when nothing works while everything seems to be okay..

Last unique row

This problem relates to report design in BIRT.
Due to limitations in the data source, I have a data set with the following rows:
Id Name Class
---------------
1 Name1 Foo
2 Name1 Bar
3 Name2 Fizz
4 Name2 Buzz
5 Name3 Baz
Duplicates of the name column should be suppressed, and only the last result should be displayed:
Id Name Class
---------------
2 Name1 Bar
4 Name2 Buzz
5 Name3 Baz
How can I do that?
(Assuming your data is in ID order)
Insert a Group in your BIRT report, on name.
Copy the detail row items into the new group footer.
Delete the detail row and new group header row.
The output from the report should match your requirements.

Resources