If i use this dojo instruction, and all work correctly.
sampleStore.query({ item_name:/^aa/}, {sort: [{attribute: "des"}]});
How can i use a variable(filter) instead of "aa" such as
var filter="aa";
sampleStore.query({ item_name:/^filter/}, {sort: [{attribute: "des"}]});//don't work
or
sampleStore.query({ item_name:/^"+filter+"/}, {sort: [{attribute: "des"}]});//don't work
You cannot use Strings in JavaScript regular expressions. If you want to do something like that you need to use new RegExp() to create a regular expression based on a string.
sampleStore.query({ item_name: new RegExp('^' + filter) }, {sort: [{attribute: "des"}]});
NOTE: If you use regular expressions this way, you cannot add the delimiter /. If you need to add modifiers like i (case insensitive /.*/i), you can do that by using:
new RegExp(".*", i);
Related
I am looking for a way to use a regex as value in a named parameter in the Java SDK. According to the documentation, there is no datatype for that, and using a String parameter does not work.
Is there any way to use a regex as value in a named parameter?
QueryParameterValue Class has no datatype for that:
https://googleapis.dev/java/google-cloud-clients/0.91.0-alpha/com/google/cloud/bigquery/QueryParameterValue.html#of-T-com.google.cloud.bigquery.StandardSQLTypeName-
A regex in the query would e.g. look like this:
REGEXP_CONTAINS(some_attribute, r"^any\sregex\ssearchstring$")
and should be replaced by a named parameter like:
REGEXP_CONTAINS(some_attribute, #named_regex_parameter)
I tried different syntax in the query like
REGEXP_CONTAINS(some_attribute, r#named_regex_parameter)
etc. but none of them worked. The #named_regex_parameter is of type String. I tried to use values in the form of r"regex_expression" and just the regex_expression in the parameter value.
Seems like I need to build the query String without a named parameter for the regex part. Any hints to solve this with parameters would be really appreciated!
//Edit: added code example how the named parameters are used in the query config
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query)
.setDestinationTable(TableId.of(destinationDataset, destinationTable))
.setAllowLargeResults(true)
.setCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
.setTimePartitioning(partitioning)
.setWriteDisposition(WriteDisposition.WRITE_APPEND)
.setParameterMode("NAMED")
.addNamedParameter("regexExpressionParam", QueryParameterValue.string(someRegexExpressionStringVariable)) //this does not work
.addNamedParameter("someStringParam", QueryParameterValue.string(stringVariable))
.setPriority(Priority.BATCH)
.build();
The query should use the parameter #regexExpressionParam like so:
REGEXP_CONTAINS(theAttributeToQuery, #regexExpressionParam))
You need to pass the regular expression string without r'...'
I had a very similar problem with running parameterized queries on Python: it was something like this.
from google.cloud import bigquery
regex_input = "^begin_word.*end_here$"
# Construct a BigQuery client object.
client = bigquery.Client()
query = """
SELECT word, word_count
FROM `bigquery-public-data.samples.shakespeare`
WHERE REGEXP_CONTAINS(word, #regex)
ORDER BY word_count DESC;
"""
job_config = bigquery.QueryJobConfig(
query_parameters=[
bigquery.ScalarQueryParameter("regex", "STRING", f"r'{regex_input}'"),
]
)
query_job = client.query(query, job_config=job_config)
At first, I thought the input had to be wrapped by r'...'; just like how I normally write a regex on BQ explorer.
I tried to modify the string input to make it like a regular expression, which was this pard f"r'{regex_input}'" of the code.
but apparently BQ correctly escapes string without our help and I can just pass down the regex string like bigquery.ScalarQueryParameter("regex", "STRING", regex_input)
I know there's similar question, but in my case the solution didn't work since there's no valid delimiter.
I have a string inside a column:
{"module-version": "2.0", "more-details-link": ""}, "has-cve": true, "issue-package": "VM-Essentials", "legacy-scan-status": "removed"}
I need the inside of issue-package. I tried:
REGEXP_EXTRACT(details_issues.issue_raw,r'\"issue-package=(.+?)\,')
But i'm getting Null inside the column. Any suggestions?
If this is a JSON string, you should use JSON_* functions instead.
You can try something like:
JSON_EXTRACT(details_issues.issue_raw, '$.issue-package')
Look at the below code
for story in book
if story.title.length < 140
- var storyTitle = story.title;
else
- var storyTitle = story.title.substring(0, 140) + '...';
.tiles
a(href= 'http://' + story.link)
img(src=story.thumbnail, width='150', height='150')
p Title: #{storyTitle}
p Date: #{story.time}
p Author: #{story.authorName}
This is working for me. However it perpllexes me that at tmes I can get away with using story.attribute and at places i must use #{story.attribute}.
For eg. if i use the line
p Title: storyTitle
without the moustaches, it simply prints the string "Title: storyTitle" in the browser.
another example, if I use img(src=#{story.thumbnail}, width='150', height='150'), it doesn't works and i get a html string (%20%20... something...) in my browser.
so what gives?
Simply said
After equal sign (=) and inside code blocks no curly braces. Everywhere else use #{}.
The difference is between the content and the attributes of tags. In the attributes, you can use the variables without braces, like
img(src=story.thumbnail
because you cant just put text in the value of attributes, it has to be a string:
img(src="/images/story.jpg")
You can't just do
img(src=/images/story.jpg)
But in the content of a tag, you have to use the hash+braces #{} so that Jade knows which bits are variables and which bits are just text.
If you want to use the hash+braces in tag attributes, you can do it like this:
img(src="#{story.thumbnail}")
I'm creating some tests with JMeter, the situation is very simple, I have a search page with a list of results, and I have to retrieve from this results some values to use in the next request.
Those results are around 350, I don't need them all.
I used the RegexExtractor to retrieve those results and it works (I setted it to retrieve just 10 results), but now I don't know how to access the results inside a LoopCounter.
The extractor put the results into a variable named Result.
The problem is that I don't know hot to build dinamically the name of a variable.
Do I have to use some function like _p()??
I can access the variable just putting the static name Result_0_g1
Inside the LoopCounter I putted also a Counter to store the loop count into the variable index
Thank you
EDIT:
SOLVED I have to write:
${__V(Result_${index}_g1)
You have to reference the variable with the function:
${__V(Result_${index}_g1)
...Just for collection.
See also this post for another implementation (case without using ForEach Controller):
ThreadGroup
HttpSampler
Regex Extractor (variableName = links)
WhileController(${__javaScript(${C} < ${links_matchNr})})
HTTPSampler use ${__V(links_${C})} to access the current result
Counter (start=1, increment=1, maximum=${links_matchNr}, referenceName=C)
Use the ForEach Controller - it's specifically designed for this purpose and does exactly what you want.
You may use ForEach Controller:
ThreadGroup
YourSampler
Regular Expression Extractor (match -1, any template)
Foreach controller
Counter(Maximum -> ${Result_matchNr} , Rf Name -> index)
LinkSamplerUsingParsedData(use -> ${__V(Result_${index}_g1)}
Now, if you want to iterate to all groups, you need another foreach to do that. As you know which group represent what value, you can use this way.
I'm having trouble getting the syntax right for a setQuery method call for multiple values, i.e.
setQuery({x : 1}) or setQuery({x : 2})
combined. Or do I need to use filter?
In case you are using Dojo Store API I think one way to query using function is described here
You can modify it like this
store.query(function(item){
return item.x == 1 || item.x == 2;
});
That will depend on the store you are using.
In order to do that easier, you should use dojox.data.AndOrReadStore
Dojo tool kit, and or read store
using that store you can use setQuery as:
yourgrid.setQuery({complexQuery:"x:1 OR x:2"});