I'm using 'bulkCreate' with 'updateOnDuplicate' option to achieve bulkUpdate, like this:
Product.bulkCreate(to_update, {
updateOnDuplicate: ['name', 'description'],
});
It works fine, but I can't find a way to get the affected rows count.
I tried adding 'updatedAt' to the fields to update and then counting the rows where 'updatedAt' is greater than the time before starting the execution. But ended up with all rows receiving CURRENT_TIMESTAMP as 'updatedAt'.
I'm sure this is a standard requirement, but then again, so is the 'bulkUpdate'.
Any ideas?
Related
I have table "BusinessHours" that contains days of the week of the store with opening Hours and Closing hours.
I want to update the values with one query! how to achieve this with sequelize ?
That's the table of the business hours and these are related to one store
Note: that in one query I want to update the whole row for each day.
In Sequelize, assuming you have a model setup for this, you can update all of the applicable days of the week that have the same hours by using the following:
await BusinessHours.update(
{
openingTime: <date>,
closingTime: <date>,
},
{
where: {
dayOfTheWeek: ['mon', 'tues', ...],
}
}
)
If you would like to update any series of days that have different values, those would have to be separate queries.
Keep in mind, you may want to include the storeId in your where statement depending on your requirements.
https://sequelize.org/api/v6/class/src/model.js~model#static-method-update
I have some spark code:
import pyspark.sql.functions as f
df=spark.read.parquet("D:\\source\\202204121920-seller_central_opportunity_explorer_category.parquet")
I have parent_ids field which is blank. I need only the records whose parent_ids are Blank. I searched into the SO and I found these answers:
df1=df.where(df["parent_ids"].isNull())
df1.toPandas()
df1=df.filter("parent_ids is NULL")
df1.toPandas()
df.filter(f.isnull("parent_ids")).show()
df.where(f.isnull(f.col("parent_ids"))).show()
Since there is clearly that parent_ids are Null, when I try to look the result I am getting 0 record counts.
Why is my result showing zero counts thoughthere are parent_ids which are blank? Any option I tired didnt worked.
I think your data is not null, it is empty :
df.where("parent_ids = ''").show()
I'm having issues sorting the following code:
I first imported the dataframe with etl
I checked if column "quantity" is numeric (raw data present innumerous errors)
I sorted the "quantity" column by the largest amounts (I tried to use 'nlargest' but it doesn't work - not sure why)
I was supposed to sort in decrescent order, I tried a bunch of different combinations but no luck.
I'm wondering if the steps chosen to solve this problem are correct, or I'm missing something in the syntax... Really appreciate any help, thnx!
table = etl.fromdataframe(df)
table = etl.select(table, 'quantity', lambda quantity: quantity.isnumeric())
table2 = etl.head(table, 5)
table
Description:
I have a table ProductGroupItems that is in a 1 to 1 relationship with BonusGroupItems and ThresholdGroupItems. Sometimes a ProductGroupItem is a bonus item other times its a threshold item. I chose this so that ProductGroupItems wouldn't have any columns that were null.
Question:
How do I insert multiple ProductGroupItems and its corresponding 1 to 1 table (Threshold or Bonus) using Sequelize.bulkCreate?
What I have tried:
Looping through values and making a separate create() each time. This does work but fires a query for EACH record, obviously.
models.ProductGroupItems.bulkCreate(productItems, { return: true }) then doing something fancy with the values that come back. This was too confusing and I ended up not being able to figure it out.
Any help?
I have the following data model:
Record: Id, ..., CreateDate
FactA: RecordId, CreateDate
FactB: RecordId, CreateDate
Relationships exist from FactA to Record and FactB to Record.
I've written measures on Records such as this with no issues:
FactA's:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA)
FactB's:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactB)
Now I'd like a count of Records with FactA but no FactB, in SQL I'd do a LEFT JOIN WHERE FactB.RecordId IS NULL but I can't figure out how to do similar in DAX. I've tried:
-- this returns blank, presumably because when there is a FactB then RecordId isn't blank, and when there is no Fact B then RecordId a NULL which isn't blank either
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA, FILTER(FactB, ISBLANK([RecordId])))
-- this returns the long "The value for columns "RecordId" in table "FactB" cannot be determined in the current context" error.
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FILTER(FactA, ISBLANK(FactB[RecordId])))
I've also tried various ways of using RELATED and RELATEDTABLE but I don't really understand enough about DAX and context to know what I'm doing.
Can someone explain how I can write the calculated measure to count Records with FactA but no FactB?
Thanks in advance.
Edit - Workaround
I've come up with this, it looks correct so far but I'm not sure if it is the generally correct way to do this:
-- Take the count with FactA and subtract the count of (FactA and FactB)
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[Id]), FactA) - CALCULATE(DISTINCTCOUNT(Records[Id]), FactA, FactB)
Here's an alternative, that might still not be the best way of doing it:
FactA_No_FactB:=CALCULATE(DISTINCTCOUNT(Records[ID]), FILTER(Records,CONTAINS(FactA, FactA[RecordID],Records[ID]) && NOT(CONTAINS(FactB,FactB[RecordID],Records[ID]))))
The difference between my version and yours is that mine returns a value of 1 for those items in and A but not B and BLANK for everything else. Your version returns 1 for those items in A but not B, 0 for those in both A and B and BLANK for everything else. Depending on your use case, one outcome may be prefereable over the other.