How to join child array value to another KTable? - ksqldb

If I have a child array (of IDs) and I would like to join by ID to another KTable, how would I go about doing this?

Related

Join tables in Hive using LIKE

I am joining tbl_A to tbl_B, on column CustomerID in tbl_A to column Output in tbl_B which contains customer ID. However, tbl_B has all other information in related rows that I do not want to lose when joining. I tried to join using like, but I lost rows that did not contain customer ID in the output column.
Here is my join query in Hive:
select a.*, b.Output from tbl_A a
left join tbl_B b
On b.Output like concat('%', a.CustomerID, '%')
However, I lose other rows from output.
You could also achieve the objective by a simple hive query like this :)
select a.*, b.Output
from tbl_A a, tbl_B b
where b.Output like concat('%', a.CustomerID, '%')
I would suggest first extract all ID's from free floating field which in your case is 'Output' column in table B into a separate table. Then join this table with ID's to Table B again to populate in each row the ID and then this second joined table which is table B with ID's to table A.
Hope this helps.

Finding the last ancestor for each record in a self-join association

I have a table Products(id, product_id, (name)...)
Each product is owned by another product (this chain can have multiple links)
The 'name' attribute is only defined on the last ancestor in the product chain, so if I want to display a list of products, i'll have to recursively query for the name of each record.
Because of this, given a list of product ids, I want to return the oldest ancestor for each one of these, so that I may eager load these instead.
Ive have tried using the recursive self join tree in postgres, but have not been able to come up with anything that works
my attempt:
self.where('products.id IN
(WITH RECURSIVE tree(id) AS (
SELECT product.id
WHERE product.id IN (?)
UNION ALL
SELECT product.id
JOIN tree ON product.id = tree.id)
SELECT id FROM tree)', product_ids)
any help is much appreciated
Thanks

HQL Query fails when using join and with clause

Good Evening,
I am using Grails and I am trying to do an HQL Query
I have an object Opportunity and inside it an object Entity and inside the Entity a collection of Titles. Each Title object can be main or not (main is a boolean field that shows which of the titles is the default one). So the query that I am doing is this:
select opportunity from Opportunity as opportunity join opportunity.entity.titles as entityTitle with entityTitle.isMain is true
But this query fails with this message:
org.hibernate.hql.ast.InvalidWithClauseException: with-clause expressions did not reference from-clause element to which the with-clause was associated.
I have tried adding the Entity and Title tables and still it fails. If I remove the with clause it works correctly but I need to filter the titles.
Thanks.
Try this query:
select distinct op from Opportunity as op
inner join op.entity as ent
inner join ent.titles as tit
with tit.isMain is true
I found the problem. First I had to join the entity to the Opportunity and then join the titles to the Opportunity. So the query is like this:
select opportunity from Opportunity as opportunity
join opportunity.entity activeEntity
with activeEntity.isActive is true
join activeEntity.titles entityTitle
with entityTitle.isActive is true

How to use association with find_by_sql in rails?

I have a long SQL query, which i am using in rails Model.find_by_sql, I have to add couple of conditions in that query like i wanted to fetch all the records whose parent.is_allowed is true.
That means i am fetching all the child elements and i wanted to use association which is between child and parent.And in the Child table we have the parent_id.
Thanks
You could try something like this:
Model.find_by_sql("select * from models where parent_id in (select id from parents where is_allowed='true') and ... ")
Just replace the ... with your original SQL query.
Edit
Based on your comment, I think this line is more what you need:
Model.find_by_sql("select * from models where parent_id in (select id from users where is_allowed='true')")

SOQL query to join one-to-one between two custom objects (Salesforce Apex)

I have two custom objects in Salesforce: Object1 and Object2
Object2 has a lookup field that references to Object1.
More than one record in Object2 could have the same Object1 record referenced.
I have to build a SOQL query wich makes a join of Object1 and Object2 where the matching is one-to-one.
ie. With those values in Object1 and Object2 I want that result:
The record in Object1 with Id=2 is not in result because it has two records in Object2 that references it.
I would like to know how to achieve this with a SOQL query.
Thanks in advance!
because you only want one row you can sneakily use aggregate functions to get you values from an aggregate query.
select max(id) object2Id,
max(name) object2Val,
max(object1__r.name) object1Val
from object2__c
group by object1__c
having count(object1__c) =1
worked for me (using the name field instead of value in my objects, but that shouldn't matter).

Resources