A compound WHERE clause in GAQL? - google-ads-api

Could you please confirm GQAL doesn't support compound WHERE clause?
FROM group_placement_view\
WHERE\
metrics.impressions >= 10000 \
AND (metrics.video_view_rate < 10' OR metrics.average_cpm > 10000 )
and not event OR as non-compound clause?
metrics.average_cpm\
FROM group_placement_view\
WHERE\
metrics.impressions >= 10000 \
OR metrics.video_view_rate < 10'

WHERE clause may only contain AND conditions https://developers.google.com/google-ads/api/docs/query/grammar

Related

how many conditions can be written on if in c ++

Hello I did one project and in my one if there were a lot of conditions about 15 I don’t remember exactly and I was wondering how many conditions can be written in if? Does anyone know this?
There should not be any hard limit on the number of 'if' in the C++ language, this could only be a limitation of your tool chain ( and potentially bad coding practice depending on the number of pages your if() statement takes)
You can go wild with them as there's no limitation as long as you put a valid boolean expression.
But having 15 conditions inside an if is a crime. There must be some way you can clean that up. Maybe you can put some of those conditions that have something in common in boolean variables.
Then you do something like this:
bool var1 = condition1 && condition2 && ... && condition10
bool var2 = condition11 && condition12 && ... && condition15
if(var1 && var2){
Do stuff
}

How to disable 'experimental' warning?

I love chained relational feature (e.g. 0 < a < b that replaces 0 < a && a < b) ... but the feature is experimental currently. How to disable/ignore 'experimental' warning?
Pass --enable-experimental to valac.

How to refactor huge lookup table in Ruby

I have a method:
def assign_value
...
#obj.value = find_value
end
and a huge lookup table:
def find_value
if #var > 0 && #var <= 30
0.4
elsif #var > 30 && #var <= 50
0.7
elsif #var > 50 && #var <= 70
1.1
elsif #var > 70 && #var <= 100
1.5
elsif #var > 100 && #var <= 140
2.10
elsif #var > 140 && #var <= 200
2.95
elsif #var > 200 && #var <= 300
4.35
elsif #var > 300 && #var <= 400
6.15
elsif #var > 400 && #var <= 500
7.85
elsif #var > 500 && #var <= 600
9.65
...
end
and so on for 1800 lines.
Needless to say, it's for the tax department of an unnamed country. Right now, it's written manually (all 1800 lines of it) to account the varying length of the integer ranges and decimal return values.
Without rewriting an entire country's tax code, how would I refactor this?
The ranges and values do change on a yearly basis, and we need to maintain backwards compatibility. A database table would simplify matters, but because we're dealing with a number of different countries, each with different requirements and tax codes, creating a database table isn't as straightforward as it sounds.
#MilesStanfield's answer has pretty much the same impact as yours. As said in my comment, I would use a hash to get rid of all conditions (or cases):
COUNTRY_TAX_RATES = {
0..30 => 0.4,
31..50 => 0.7,
51..70 => 1.1
}
COUNTRY_TAX_RATES[0..30] # 0.4
COUNTRY_TAX_RATES.select { |code| code === 10 }.values.first # 0.4
If you don't change the codes often you could use this. If it does change frequently you might consider using another approach (for example, store in db and manage through an user interface).
UPDATE: Now I'm no longer on my mobile I want to expand this answer a little bit further. It seems you are disregarding #Wand Maker's proposal, but I don't think you should.
Imagine you use my hash. It is convenient, without any conditionals and easy to adjust. However, as Wand Maker points out, everytime either the range or decimal changes you need a developer to update the code. This might be ok, because you only have to do it on a yearly basis, but it is not the cleanest approach.
You want accountants to be able to update the tax rates and codes, instead of developers. So you should probably create a table which contains these attributes. I'm not sure what the ranges and decimals stand for in your example, but I hope you get the idea:
Tax (ActiveRecord) with range_column (Give this an explicit, explanatory name. You could also use min and max range columns), code, rate and country_id
class Tax < ActiveRecord::Base
serialize :range_column
belongs_to :country
end
Country has_many :taxes
If you want to know the tax rate for malta (country_id: 30), with tax code 40 (whatever this might mean) you could do something like this:
Tax.select(:tax_rate).joins(:country).find_by(country_id: 30, range_column: 40).tax_rate # you might need a between statement instead, can't check right now if querying a serialized hash works like this
Now an accountant can update the ranges, decimals or any other attribute when these change (of course you have to build a CRUD for it first).
P.s. Don't mind the naming, not sure what these numbers represent. :)
I would use a case statement with ranges
case #var
when 0..30 then 0.4
when 31..50 then 0.7
when 51..70 then 1.1
...
end
Suppose inc is income and arr is an array of pairs [bp, tax], where
arr[0][0] = 0, meaning bp (income "breakpoint") for the first element of arr is zero;
arr[i][0] < arr[i+1][0], meaning breakpoints are increasing;
tax arr[-1][1] is payable if inc >= arr[-1][0]; and
tax arr[i][1] is payable if arr[i][0] <= inc < arr[i+1][0], 0 <= i <= arr.size-2.
Tax can then be computed
arr.find { |bp,_| inc >= bp }.last
since the breakpoints are increasing.

How can I revert syntax from Cypher 2.0.1 to Cypher 2.0.0 for my Neo4j queries?

I am using a series of nested FOREACH loops in a query that functions properly on a number of installations of Neo4j with matching datasets that we've used for testing. With the recent change to Cypher 2.0.1, my query doesn't work.
My initial instinct is to replace the /var/lib/neo4j/lib/neo4j-cypher-2.0.0.jar files, but I don't want to screw things up. Any thoughts?
Sample graph: http://console.neo4j.org/?id=ktrcwx
Here's the Query (my emphasis "**" indicates the point where error occurs):
$ MATCH (total:Recipe)
> WITH count(DISTINCT total) AS tots, timestamp() AS time
> MATCH (ia:Ingredient)<-[:HAS_INGREDIENT]-(recab:Recipe)-[recHasB:HAS_INGREDIENT]->(ib:Ingredient)
> WHERE id(ia)=5167
> WITH DISTINCT ib AS idB, count(DISTINCT recab) AS recAB , count(DISTINCT recHasB) AS recB, tots, time
> MATCH (i:Ingredient)<-[:HAS_INGREDIENT]-(r:Recipe)
> WHERE id(i)=5167
> WITH [i, count(DISTINCT r.id), idB, recAB, recB, tots, time] AS c
> FOREACH (row IN c |
> FOREACH (i1 in **c[0] |**
> FOREACH (recA in c[1] |
> FOREACH (i2 in c[2]|
> FOREACH (recAB in c[3] |
> FOREACH (recB in c[4] |
> FOREACH (totalRec in c[5] |
> CREATE (i1:Ingredient )-[pm1:PMI]->(i2: Ingredient)
> SET startNode(pm1).pmiTime = c[6], endNode(pm1).pmiTime = c[6], pm1.weight = log( (totalRec*recAB) /(recA*recB) ), pm1.pmiTime= c[6]
> CREATE (i1:Ingredient )<-[pm2:PMI]-(i2: Ingredient)
> SET startNode(pm2).pmiTime = c[6], endNode(pm2).pmiTime = c[6], pm2.weight = log( (totalRec*recAB) /(recA*recB) ), pm2.pmiTime= c[6]
> )
> )
> )
> )
> )
> )
> );
Here's the Error:
SyntaxException: Type mismatch: expected Collection<T> but was Any (line 10, column 25)" FOREACH (i1 in c[0] |"
Here's the Functioning Classpath:
Neo4j Server is running at pid 4347
NEO4J_HOME: /var/lib/neo4j
NEO4J_SERVER_PORT: 7474
NEO4J_INSTANCE: /var/lib/neo4j
JAVA_HOME:
JAVA_OPTS: -server -XX:+DisableExplicitGC -Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
CLASSPATH: /var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:/var/lib/neo4j/lib/geronimo-jta_1.1_spec-1.1.1.jar:/var/lib/neo4j/lib/lucene-core-3.6.2.jar:/var/lib/neo4j/lib/neo4j-cypher-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-commons-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-1.9-2.0.0.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-2.0-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-algo-2.0.0.jar:/var/lib/neo4j/lib/neo4j-graph-matching-2.0.0.jar:/var/lib/neo4j/lib/neo4j-jmx-2.0.0.jar:/var/lib/neo4j/lib/neo4j-kernel-2.0.0.jar:/var/lib/neo4j/lib/neo4j-lucene-index-2.0.0.jar:/var/lib/neo4j/lib/neo4j-shell-2.0.0.jar:/var/lib/neo4j/lib/neo4j-udc-2.0.0.jar:/var/lib/neo4j/lib/org.apache.servicemix.bundles.jline-0.9.94_1.jar:/var/lib/neo4j/lib/parboiled-core-1.1.6.jar:/var/lib/neo4j/lib/parboiled-scala_2.10-1.1.6.jar:/var/lib/neo4j/lib/scala-library-2.10.3.jar:/var/lib/neo4j/lib/server-api-2.0.0.jar:/var/lib/neo4j/system/lib/asm-3.1.jar:/var/lib/neo4j/system/lib/bcprov-jdk16-140.jar:/var/lib/neo4j/system/lib/commons-beanutils-1.8.0.jar:/var/lib/neo4j/system/lib/commons-beanutils-core-1.8.0.jar:/var/lib/neo4j/system/lib/commons-collections-3.2.1.jar:/var/lib/neo4j/system/lib/commons-compiler-2.6.1.jar:/var/lib/neo4j/system/lib/commons-configuration-1.6.jar:/var/lib/neo4j/system/lib/commons-digester-1.8.1.jar:/var/lib/neo4j/system/lib/commons-io-1.4.jar:/var/lib/neo4j/system/lib/commons-lang-2.4.jar:/var/lib/neo4j/system/lib/commons-logging-1.1.1.jar:/var/lib/neo4j/system/lib/jackson-core-asl-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-jaxrs-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-mapper-asl-1.9.7.jar:/var/lib/neo4j/system/lib/janino-2.6.1.jar:/var/lib/neo4j/system/lib/javax.servlet-3.0.0.v201112011016.jar:/var/lib/neo4j/system/lib/jcl-over-slf4j-1.6.1.jar:/var/lib/neo4j/system/lib/jersey-core-1.9.jar:/var/lib/neo4j/system/lib/jersey-multipart-1.9.jar:/var/lib/neo4j/system/lib/jersey-server-1.9.jar:/var/lib/neo4j/system/lib/jetty-http-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-io-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-security-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-server-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-servlet-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-util-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-webapp-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-xml-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jsr311-api-1.1.2.r612.jar:/var/lib/neo4j/system/lib/logback-access-1.0.9.jar:/var/lib/neo4j/system/lib/logback-classic-1.0.9.jar:/var/lib/neo4j/system/lib/logback-core-1.0.9.jar:/var/lib/neo4j/system/lib/mimepull-1.6.jar:/var/lib/neo4j/system/lib/neo4j-browser-2.0.0.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.0-static-web.jar:/var/lib/neo4j/system/lib/rhino-1.7R3.jar:/var/lib/neo4j/system/lib/rrd4j-2.0.7.jar:/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:/var/lib/neo4j/conf/
Here's the Malfunctioning Classpath:
Neo4j Server is running at pid 1361
NEO4J_HOME: /var/lib/neo4j
NEO4J_SERVER_PORT: 7474
NEO4J_INSTANCE: /var/lib/neo4j
JAVA_HOME:
JAVA_OPTS: -server -XX:+DisableExplicitGC - Dorg.neo4j.server.properties=conf/neo4j-server.properties -Djava.util.logging.config.file=conf/logging.properties -Dlog4j.configuration=file:conf/log4j.properties -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled
CLASSPATH: /var/lib/neo4j/lib/concurrentlinkedhashmap-lru-1.3.1.jar:/var/lib/neo4j/lib/geronimo-jta_1.1_spec-1.1.1.jar:/var/lib/neo4j/lib/lucene-core-3.6.2.jar:/var/lib/neo4j/lib/neo4j-cypher-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-commons-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-1.9-2.0.1.jar:/var/lib/neo4j/lib/neo4j-cypher-compiler-2.0-2.0.1.jar:/var/lib/neo4j/lib/neo4j-graph-algo-2.0.1.jar:/var/lib/neo4j/lib/neo4j-graph-matching-2.0.1.jar:/var/lib/neo4j/lib/neo4j-jmx-2.0.1.jar:/var/lib/neo4j/lib/neo4j-kernel-2.0.1.jar:/var/lib/neo4j/lib/neo4j-lucene-index-2.0.1.jar:/var/lib/neo4j/lib/neo4j-shell-2.0.1.jar:/var/lib/neo4j/lib/neo4j-udc-2.0.1.jar:/var/lib/neo4j/lib/org.apache.servicemix.bundles.jline-0.9.94_1.jar:/var/lib/neo4j/lib/parboiled-core-1.1.6.jar:/var/lib/neo4j/lib/parboiled-scala_2.10-1.1.6.jar:/var/lib/neo4j/lib/scala-library-2.10.3.jar:/var/lib/neo4j/lib/server-api-2.0.1.jar:/var/lib/neo4j/system/lib/asm-3.1.jar:/var/lib/neo4j/system/lib/bcprov-jdk16-140.jar:/var/lib/neo4j/system/lib/commons-beanutils-1.8.0.jar:/var/lib/neo4j/system/lib/commons-beanutils-core-1.8.0.jar:/var/lib/neo4j/system/lib/commons-collections-3.2.1.jar:/var/lib/neo4j/system/lib/commons-compiler-2.6.1.jar:/var/lib/neo4j/system/lib/commons-configuration-1.6.jar:/var/lib/neo4j/system/lib/commons-digester-1.8.1.jar:/var/lib/neo4j/system/lib/commons-io-1.4.jar:/var/lib/neo4j/system/lib/commons-lang-2.4.jar:/var/lib/neo4j/system/lib/commons-logging-1.1.1.jar:/var/lib/neo4j/system/lib/jackson-core-asl-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-jaxrs-1.9.7.jar:/var/lib/neo4j/system/lib/jackson-mapper-asl-1.9.7.jar:/var/lib/neo4j/system/lib/janino-2.6.1.jar:/var/lib/neo4j/system/lib/javax.servlet-3.0.0.v201112011016.jar:/var/lib/neo4j/system/lib/jcl-over-slf4j-1.6.1.jar:/var/lib/neo4j/system/lib/jersey-core-1.9.jar:/var/lib/neo4j/system/lib/jersey-multipart-1.9.jar:/var/lib/neo4j/system/lib/jersey-server-1.9.jar:/var/lib/neo4j/system/lib/jetty-http-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-io-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-security-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-server-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-servlet-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-util-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-webapp-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jetty-xml-9.0.5.v20130815.jar:/var/lib/neo4j/system/lib/jsr311-api-1.1.2.r612.jar:/var/lib/neo4j/system/lib/logback-access-1.0.9.jar:/var/lib/neo4j/system/lib/logback-classic-1.0.9.jar:/var/lib/neo4j/system/lib/logback-core-1.0.9.jar:/var/lib/neo4j/system/lib/mimepull-1.6.jar:/var/lib/neo4j/system/lib/neo4j-browser-2.0.1.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.1.jar:/var/lib/neo4j/system/lib/neo4j-server-2.0.1-static-web.jar:/var/lib/neo4j/system/lib/rhino-1.7R3.jar:/var/lib/neo4j/system/lib/rrd4j-2.0.7.jar:/var/lib/neo4j/system/lib/slf4j-api-1.6.2.jar:/var/lib/neo4j/conf/
Notes on intended outcome:
For every row in the collection, the query should create 2 relations: (i1)-[:PMI]->(i2) and (i2)-[:PMI]->(i1). The weight of the [:PMI] relations is the math in the Log() function. The graph is (:Ingredient) and (:Recipe) nodes. This query will create a relationship between (i1:Ingredient) and every (i2:Ingredient) that occurs in the recipe containing (i1). This allows me to understand probability of ingredient pairings.
Can you wrap your non-collection items in [ ] and see if that solves the problem? For example: FOREACH(i1 IN [c[0]] |
Ok, here's an attempt at a slight rewrite that compiles--would be great if you could post some example data on console.neo4j.org if it doesn't work:
MATCH (total:Recipe)
WITH count(DISTINCT total) AS tots, timestamp() AS time
MATCH (ia:Ingredient)<-[:HAS_INGREDIENT]-(recab:Recipe)-[recHasB:HAS_INGREDIENT]->(ib:Ingredient)
WHERE id(ia)=5167
WITH DISTINCT ib AS idB, count(DISTINCT recab) AS recAB , count(DISTINCT recHasB) AS recB, tots, time
MATCH (i:Ingredient)<-[:HAS_INGREDIENT]-(r:Recipe)
WHERE id(i)=5167
WITH i, count(DISTINCT r.id) as recA, idB as i2, recAB, recB, tots, time
CREATE (i)-[pm1:PMI {pmiTime:time, weight:log( (tots*recAB) /(recA*recB) )}]->(i2)
CREATE (i)<-[pm2:PMI {pmiTime:time, weight:log( (tots*recAB) /(recA*recB) )}]-(i2)
SET i.pmiTime = time, pm1.pmiTime = time, i2.pmiTime = time, pm2.pmiTime = time

eliminating "not "in the expression using z3

I try to eliminate "not" in the expression using the script http://rise4fun.com/Z3/XwGt however, it doesn't work, there is still not in the result, would someone help me?
The output goals in your example are in simplified formula. There is no redundant assertion in any goal. The Z3 simplified form always use non-strict inequalities such as t1 <= t2 and t1 >= t2. Strict inequalities such as t1 < 0 are encoded using negation. That is, t1 < 0 is encoded as not t1 >= 0. The idea is to reduce the number of atoms used to encode a big formula.
It would be useful to understand why you need to eliminate the nots in the output. If there is an useful application for that, we will include a new tactic (in the next release) that performs the transformation.

Resources