In MarkLogic and xquery, I need to negate looking for a collection on a document , so I tried:
( fn:index-of(xdmp:document-get-collections($found-uri ),"/catalog/") eq () )
When that statement is true the record is not in the catalog.
However, executing that statement on a document not in that collection, I don't get "true"; it returns false.
fn:index-of(xdmp:document-get-collections($found-uri ),"/catalog/") returns "empty sequence" in QConsole.
So when I test it for () I should get "true", right?
When you compare an empty sequence to an empty sequence: () eq () it returns false
To test whether any of the collections are equal to "/catalog/" you could use:
xdmp:document-get-collections($found-uri ) = "/catalog/"
To negate that, use not():
not(xdmp:document-get-collections($found-uri ) = "/catalog/")
The following:
not("no-match" = "/catalog/"),
not(("no-match", "/catalog/") = "/catalog/"),
not(() = "/catalog/")
Returns:
true,
false,
true
Related
Recent airflow-providers-amazon has deprecated MySQLToS3Operator and introduced SqlToS3Operator and now it is adding an index column in the beginning of the CSV dump.
For example, if I run the following
sql_to_s3_task = SqlToS3Operator(
task_id="sql_to_s3_task",
sql_conn_id=conn_id_name,
query="SELECT created_at, score FROM my_table",
s3_bucket=bucket_name,
s3_key=key,
replace=True,
)
The S3 file has something like this:
,created_at,score
1,2023-01-01,5
2,2023-01-02,6
The output seems to be a direct dump from Pandas. How can I remove this unwanted preceding index column?
The operator uses pandas DataFrame under the hood.
You should use pd_kwargs. It allows you to pass arguments to include in DataFrame .to_parquet(), .to_json() or .to_csv().
Since your output is csv the relevant pandas.DataFrame.to_csv parameters are:
header: bool or list of str, default True
Write out the column names. If a list of strings is given it is assumed to be aliases for the column names.
index: bool, default True
Write row names (index).
Thus you can do:
sql_to_s3_task = SqlToS3Operator(
task_id="sql_to_s3_task",
sql_conn_id=conn_id_name,
query="SELECT created_at, score FROM my_table",
s3_bucket=bucket_name,
s3_key=key,
replace=True,
file_format="csv",
pd_kwargs={"index": False, "header": False},
)
Create a empty element to a list, and return True value with "Should Be True" key word. but not suiteable for create a empty variable.Why is that?
code:
${list1} Create List ${EMPTY}
${list2} Set Variable ${EMPTY}
Should Be True ${list1} Create empty list
Should Be True ${list2} Set empty variable
Log:
20211225 14:24:58.913 : INFO : ${list1} = ['']
20211225 14:24:58.916 : TRACE : Arguments: [ '' ]
20211225 14:24:58.916 : TRACE : Return: ''
20211225 14:24:58.917 : INFO : ${list2} =
20211225 14:24:58.918 : TRACE : Arguments: [ [''] | 'Create empty list' ]
20211225 14:24:58.918 : TRACE : Return: None
20211225 14:24:58.919 : TRACE : Arguments: [ '' | 'Set empty variable' ]
20211225 14:24:58.920 : FAIL : Evaluating expression '' failed: ValueError: Expression cannot be empty.
It is a bit counter-intuitive because ${list1} Create List ${EMPTY} is not creating an empty list, but a list with an empty element inside, e.g. [''], while ${list2} Set Variable ${EMPTY} will create an empty variable, e.g. ''. This is why Should Be True passes on the list (list is not empty) but fails on the variable (variable is empty).
Below code exemplifies these cases:
# empty_list == []
${empty_list} = Create List
log to console ${empty_list}
should be empty ${empty_list}
# empty_list_1 == ['']
${empty_list_1} = Create List ${EMPTY}
log to console ${empty_list_1}
should not be empty ${empty_list_1}
# empty_var == '' (empty string with length 0)
${empty_var} = Set Variable
log to console ${empty_var}
should be empty ${empty_var}
# empty_var_1 == '' (empty string with length 0)
${empty_var_1} = Set Variable ${EMPTY}
log to console ${empty_var_1}
should be empty ${empty_var_1}
I have this jq filter:
some_command | jq -r '.elements[] | select(.state=="LIVE" and .group == "some_text" and .someFlag == false) | .name'
someFlag is an optional field. Hence, when it is absent, the expression doesn't show any result. I want to check for:
if someFlag is present, pass the check only if it has the false value
if someFlag is not present, treat it as false
How can I do that?
I used the alternative operator, //:
(.someFlag // false) == false)
So, if .someFlag isn't there, it is treated as false.
The whole expression is:
some_command | jq -r '.elements[] | select(.state=="LIVE" and .group == "some_text" and (.someFlag // false) == false)) | .name'
From jq documentation:
Alternative operator //:
A filter of the form a // b produces the same
results as a, if a produces results other than false and null.
Otherwise, a // b produces the same results as b.
This is useful for providing defaults: .foo // 1 will evaluate to 1 if
there’s no .foo element in the input. It’s similar to how or is
sometimes used in Python (jq’s or operator is reserved for strictly
Boolean operations).
In the given context, the direct translation of:
if someFlag is present, pass the check only if it has the false value
if someFlag is not present, treat it as false
to jq is:
if has("someflag") then .someflag == false else false end
Adjusted filter
.elements[]
| select(.state == "LIVE"
and .group == "some_text"
and (if has("someFlag")
then .someFlag == false
else false
end))
| .name
[This response has been updated in accordance with the update to the Q.]
I want to access the GetDeepSearchResults info from the Zillow API.
My code:
library(ZillowR)
zapi_key = getOption('Myapikey')
GetDeepSearchResults(
address = '600 S. Quail Ct.',
zipcode = '67114',
rentzestimate = FALSE,
api_key = zapi_key
)
Error:
Error in GetDeepSearchResults(address = "600 S. Quail Ct.", zipcode = "67114", :
unused arguments (zipcode = "67114", api_key = zapi_key)
Why does this error occur? What can I do to fix this?
Edit: I changed the code according to the comments and got this:
My code:
library(ZillowR)
zapi_key = getOption('myapikey')
GetDeepSearchResults(
address = '600 S. Quail Ct.',
citystatezip = '67114',
rentzestimate = FALSE,
zws_id = 'myapikey',
url = "http://www.zillow.com/webservice/GetDeepSearchResults.htm"
)
Output:
$request
$request$address
NULL
$request$citystatezip
NULL
$message
$message$text
[1] "Error: invalid or missing ZWSID parameter"
$message$code
[1] "2"
$response
NULL
How can I fix this?
The unused arguments error is typical when you pass arguments, which are not parts of the function. So R doesn't know what to do with those and returns the error. You can check the documentation of the function with ?GetDeepSearchResults
This shows you the usage:
GetDeepSearchResults(address = NULL, citystatezip = NULL,
rentzestimate = FALSE, zws_id = getOption("ZillowR-zws_id"),
url = "http://www.zillow.com/webservice/GetDeepSearchResults.htm")
To have this work, you have to set your id first with (you can create an id on https://www.zillow.com/howto/api/APIOverview.htm):
set_zillow_web_service_id("youractualkey")
So you function does not have the argument zipcode and api_key. Let's change your arguments to some which exist:
GetDeepSearchResults(address='600 S. Quail Ct.', citystatezip ='67114',
rentzestimate=FALSE)
You surely recognized I did not use your api_key. This is because the default:zws_id = getOption("ZillowR-zws_id") calls your global 'ZillowR-zws_id' which you just set with the set_zillow_web_service_id() command. So it's not necessary to change the default value. But you can skip this when you use zws_id ="youractualkey" from zillow
I made a random account I set up for validating. This gives me the output:
$request
$request$address
NULL
$request$citystatezip
NULL
$message
$message$text
[1] "Error: this account is not authorized to execute this API call"
$message$code
[1] "6"
$response
NULL
So I could successfully contact the server and my key was recognized. The account authority is not R related and has to be set on the website.
declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where ($c/encompassed/#continent = 'f0_119') and ($c/#population < 100000)
return concat('Country: ',$c/name, ', Population: ',$c/#population);
it returns:
Type Error: Type of value '
()
' does not match sequence type: xs:anyAtomicType?
At characters 11681-11698
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67
At File "q2_3.xq", line 4, characters 13-67
however, if i do not do a concat return, just name or population it will work, and most strange thing is i have another program :
declare variable $fb := doc("factbook.xml")/mondial;
for $c in $fb//country
where $c/religions = 'Seventh-Day Adventist'
order by $c/name
return concat('Country: ',$c/name, ', Population: ',$c/#population);
The return syntax is exactly same, however, it works.
Why this happens?
Without seeing an example of your data it's impossible to say for sure, but if $c/name returns more than one value, then your error would make sense. Do you have any results where there are more than one name element?