Code running in Dbeaver but not working when I implement the same via dbt - amazon-redshift

I am new to this thing and I have a doubt. I am migrating flows from tableau prep to dbt. There is this filter that is used in prep which goes like
NOT ((([Tactic] == "Awareness") AND NOT (ISNULL([Tactic]))))
and my corresponding code is like : (tactic = 'Awareness' and tactic is not null) = false,
tactic is a calculated field where we are deriving the values of tactic from other fields.
This code runs perfectly fine when I am using my sql editor(dbeaver) but does not give me proper values when I run it in DBT Awareness is included in the dbt output.
Here are the versions :
DBT: 1.2.2
postgres: 1.2.2
redshift: 1.2.0
The packages cannot be upgraded as these will create issues in other flows that are being derived from my own flow.
has anyone else encountered a same issue or can someone please help me out with this?
I have tried doing tactic <> 'Awareness'.

There is a subtle bug here related to null handling that could be causing this.
For null values, tactic = 'Awareness' will be null, and null and true will also be null, which is not equal to false.
Generally, comparisons to booleans in Redshift should use is false, not = false, and in this case, you really want not ... is true, not is false, since not (null is true) is true, but null is false is false.
I'd refactor this whole thing to something less dependent on the specifics of null handling for boolean operators for your database:
coalesce(tactic, '') <> 'Awareness'

Related

Lack of null inequality support in Firestore's PHP SDK

We are able to run null inequality just fine on the JavaScript SDK (client or admin), but we are unable to in PHP? To me it seems this is a backend feature which is already supported by Firestore, but throws an error in PHP.
->where('preorders', '!=', null)
Uncaught InvalidArgumentException: Null and NaN are allowed only with operator EQUALS.
Whereas the equivalent in JS SDK works just fine.
query(q, where('preorders', '!=', null))
Since I cannot open an issue in google's PHP SDK repo here, is there any way we can find a reason as to why this is not possible?
The documentation says, :
“A field exists when it's set to any value, including an empty string (" "), null, and NaN (not a number). Note that null field values do not match != clauses, because x != null evaluates to undefined.”
Explanation : Yes, even if we add an empty string, null,( supported data type in Firestore) or NaN, it doesn't mean that the field doesn't exist. It definitely exists and holds one of those values. And coming to when we compare x != null in where clauses, x != null evaluates undefined, but for non-exist fields. And undefined is not a supported data type in Firestore, according to this Firestore supported data type.
So we can compare .where(x!=null) and it is supported, but it evaluates to undefined for non-existent fields.
As mentioned in similar thread, the version release of v7.21.0 in Firestore JS SDK supports the != operator with where clause from version 7.21.0
But while digging deeper in the documentation, I found that php5 supports != operator as you can see in the code snippet, but the php8 does not support != operator yet and the workaround is using not-in instead of it as shown in this code snippet.
Maybe you are trying to use php version >5 and hence the error.
There is already an open issue on this, in GitHub. You may follow the link for updates and changes or you can create a new request here.

What is the difference between `ARRAY[(value'::text]` and `ARRAY['value']::text[]`

This shows up in our schema.rb diff sometimes, and I asked my team around and it seems they all have the same postgresql version. With a conditional index, the dumped schema sometimes look like this:
t.index ["field_name"], name: "irrelevant", unique: true,
where: "((state))::text = ANY (ARRAY[('applied'::character varying)::text]))"
and sometimes like that:
t.index ["field_name"], name: "irrelevant", unique: true,
where: "((state))::text = ANY (ARRAY['applied'::character varying]::text[]))"
so the difference seems to be only with the way the casting is expressed:
ARRAY['string'::text]
// vs
ARRAY['string']::text[]
It seems to me those two castings are equivalent. So my first question is: Are they?
And my second question: where is this discrepancy coming from? As mentioned before all my teammates seem to have the same PGSQL version (though there might be a few missing data points). They definitely have the same rails version, so that can't be the source.
The two syntax variants have the same meaning, and PostgreSQL treats them the same. The difference you observe is not caused by a version difference in PostgreSQL, but perhaps in Ruby on Rails.

Filtering column strings that contain substring

I am working on an if else in the Tmap, and one of the conditions is if a column contains a substring.
I am unsure exactly how to go about this being fairly new to talend.
This is the current syntax that I am using.
row16.Location.contains("clos")?"Pending":""
I have not been able to find any good examples of the correct way to go about this, other than the one above.
Talend uses Java as an underlying language, so you need to use the ternary operator of Java:
row16.Location.contains("clos") ? "Pending" : ""
But make sure you first check row16.Location for null, otherwise you'll get a NullPointerException if Location is null :
row16.Location != null && row16.Location.contains("clos") ? "Pending" : ""

Reuse of conditions (when) in Drool DSL statements

Is it possible to reuse a when/condition statement into another when/condition statement in a DSL file?
For example, I have two conditions:
[condition][]The client is invalid = Client( name == null || email == null )
[condition][]All the clients are invalid = forall( Client( name == null || email == null ) )
Note that the second condition just diff the first for the forall command, but the statement inside is equals. In these case, I want to reuse the first condition into the second.
Is it possible? How?
Thank you.
even the most recent version of drools will only let you substitute values into a template from pojo's or a corresponding map as per their documentation here.
This won't work for your use case though.
Since drool files are simply text files, there is nothing preventing you from considering a more powerful templating toolkit.
Possibilities include Apache Velocity, ANTLR or Scala!

Rails - Heroku Postgresql SQL Error - Works on Local SQLite - Error "ActiveRecord:Invalid Relation"

Hi here is my ActiveRelation query that works fine on local development environment (SQLite)
#table2_items = #table1var.table2_items.find(:all, conditions: ["status1 is ? AND status2 is ? AND start_datetime > ?", true, nil, Time.now.to_datetime], order: [:field_id, :created_at])
I think it's just a syntax error... Can anyone help? Thanks
Your SQL ends up with this in it:
status1 is 't'
and that's invalid: is is only used with is null, is distinct from, and similar constructs.
You should upgrade to a more modern syntax and leave most of the work to ActiveRecord:
#table2_items = #table1var.table2_items
.where(:status1 => true, :status2 => nil)
.where('start_datetime > ?', Time.now)
.order(:field_id, :created_at)
That leaves most of the "how do I compare things?" logic up ActiveRecord and is a bit easier to read as the placeholders and their values aren't separated from each other.
Once you have this problem sorted out, you really should install PostgreSQL in your development environment so that you're developing and deploying on the same stack. There are all sorts of differences between databases that no ORM can protect you from.