I get a parse error with an AQL query that includes a numeric literal with a value 'x' where
-1 < x < 1 and x != 0, and where the leading zero is omitted, such as x < .5 or x > -.2.
I think this may be a bug, but the documentation doesn't clearly state whether a leading zero is required or not (seems odd that it would be required).
I'm only running version 3.4 rc4, so I can't verify if this behavior is present with any officially released versions. Can someone confirm? Or are there any ArangoDB devs on here that care to comment?
Thanks!
AQL does not support floating point number literals without leading digit.
The documentation shows examples of supported notations, and one like .5 is not among them.
If you want to propose this as feature, create an issue on GitHub.
You can find the code that defines the language tokens for numbers here:
https://github.com/arangodb/arangodb/blob/devel/arangod/Aql/tokens.ll#L447
(0|[1-9][0-9]*) {
/* a numeric integer value */
...
(0|[1-9][0-9]*)((\.[0-9]+)?([eE][\-\+]?[0-9]+)?) {
/* a numeric double value */
As can be seen from these regular expressions, literals like 00 and 00.123 are not supported either - there must not be more than one leading 0 in the integer part.
Ran this in 3.3.19 and runs fine:
let tmp = [0.2,3,4,0.5]
for t in tmp
filter t > 0.5
return t
This throws a parsing error
let tmp = [0.2,3,4,0.5]
for t in tmp
filter t > .5
return t
So, I would think it is safe to say that the 0 is mandatory
Update
We recently merged a pull request into the devel branch of ArangoDB that adds support for fractional numbers without leading zeros to AQL. This is available in the ArangoDB development version from next build onwards, but not available in any release yet. So far, target release would be 3.5.
If there is popular demand for the feature, it should be easy to backport the pull request to ArangoDB 3.4 as well.
Related
This question represents a proposed bug for Globalize. The owners of that project ask that it first be published as a SO question, so here we go...
With the new version 1.2.1 (and 1.2.2) of Globalize we're noticing that number-parsing an empty string returns 0 (seemingly independent of culture). This behavior is different to the previous version 1.1.2, where it returned NaN. Reproduction:
var g = new Globalize("en-US");
g.numberParser()(''); // returns 0 in v1.2.1 and NaN in v1.1.2.
Intuition tells me that parsing an empty string should not return 0. Vanilla JavaScript parse functions (e.g. parseInt) return NaN in such cases, supporting this intuition.
Furthermore, the relevant unit test in the Globalize project does not seem to cover this case, so it's unclear whether or not the changed behavior is intended. From a brief look at the changelog of the 1.2.* releases I can't seem to find any note of an intention to change this behavior.
Note that parsing whitespace in the new version does indeed return NaN:
var g = new Globalize("en-US");
g.numberParser()(' '); // returns NaN in both v1.2.1 and v1.1.2.
We're hoping that one of the project members will either confirm that this is a bug and raise a corresponding issue in the Globalize project, or explain why this is now expected behavior.
It's a bug, thanks for reporting, will be tracked in https://github.com/globalizejs/globalize/issues/682
I need to return a floating point number via a scripted field in Kibana 4 (beta 3). The scripted field needs to perform a division on an integer ( > 0 ) field stored in the elasticsearch index as in:
1 / field-value
The scripted fields use Groovy, therefore I tried...
1.0 / doc["integer-field"].value
...but that doesn't seem to have worked. I was under the impression that the use of 1.0 would cast the result to a floating point number - I seem to be getting infinity plotted on my line chart.
Totally new to Groovy and Kibana so I've probably got the syntax wrong.
Any help would be very much appreciated.
I tried the following snippet of Alloy4, and found myself confused by the behavior of the util/Natural module. The comments explain more in detail what was unexpected. I was hoping someone could explain why this happens.
module weirdNatural
private open util/natural as nat
//Somehow, using number two obtained from incrementing one works as I expect, (ie, there is no
//number greater than it in {0,1,2}. but using number two obtained from the natrual/add function
//seems to work differently. why is that?
let twoViaAdd = nat/add[nat/One, nat/One]
let twoViaInc = nat/inc[nat/One]
pred biggerAdd {
some x: nat/Natural | nat/gt[x, twoViaAdd]
}
pred biggerInc {
some y: nat/Natural | nat/gt[y, twoViaInc]
}
//run biggerAdd for 10 but 3 Natural //does not work well, it does find a number gt2 in {0,1,2}
run biggerInc for 10 but 3 Natural //works as expected, it finds a number gt2 in {0,1,2,3}, but not in {0,1,2}
Thanks for this bug report. You are absolutely right, that is a weird behavior.
Alloy4.2 introduced some changes to how integers are handled; namely, the + and - operators in Alloy4.2 are always interpreted as set union/difference, so built-in functions plus/minus have to be used to express arithmetic addition/subtraction. On the other side, the util/natural module (mistakenly) hasn't been updated to use the latest syntax, which was the root cause of the weird behavior you experienced (specifically, the nat/add function uses the old + operator instead of plus, whereas nat/inc doesn't).
To work around this issue, you can either
open the util/natural module (choose "File -> Open Sample Models" from the main menu)
edit the file and replace the two occurrences of <a> + <b> with plus[<a>, <b>]
save the new file in the same folder with your model als file (e.g., as "my_nat.als")
open it from your main module (e.g., open my_nat as nat)
or
download the latest unofficial version where this bug is fixed (you might need to manually delete the Alloy temp folder to make sure that the Alloy Analyzer is not using the old (cached) version of the util/natural library).
I am looking for snippet which will check which version is available to download for updates.
I use python 3.x. So it would be nice if anyone has a hint how i can check the version available on the server. The OUtput should generate a variable in which the version number of firefox is stored. for example 22.0
I am using linux as the operating system of my choice.
to be clear:
I don't want to know whhich version is already installed on my system. i want to know which version can be updated.
So far i got the following code:
def firefox_version_remote():
firefox_version_fresh = os.popen("curl -s -l ftp.mozilla.org/pub/mozilla.org/firefox/releases/latest/linux-i686/de/").read()
# short name for firefox version num fresh
fvnf = " "
for i in firefox_version_fresh:
if i.isalpha() != True:
fvnf = fvnf + i
return fvnf.strip()
this returns -22.0..2 where it should return 22.0
Have you considered using a regular expression to match the numbers you're trying to extract. That would be a lot easier. Something like this:
matches = re.findall(r'\d+(?:\.\d+)+', firefox_version_fresh)
if matches:
fvnf = matches[0]
That's assuming the version is of the form x.y potentially followed by more sub versions (e.g. x.y.z).
\d+ is one or more digits
(?: )+ is one or more of everything in the parentheses. The ?: tells the compiler that it's a non-capturing group - i.e. you're not interesting in extracting the data inside the parentheses as a separate group.
\.\d+ matches a dot followed by one or more digits
So the whole expression can be described as one or more digits followed by one or more occurences of a dot and one or more digits.
Does anyne know how expression engine deals with a negative offset in a list of channel entries in EE?
as in
offset="-1"
If you use offset="-1" in {exp:channel:entries}, you'll get a major MySQL error (assuming you're logged in as a super admin or are capable of seeing errors).
It's unclear what your goal is from your question. If you expect a negative offset to reverse the order (like PHP string functions), you can use use the opposite sort value. The default is desc, so sort="asc" would be the reverse. Use a positive offset="X" to skip X entries.
If you're expecting an offset like in PHP array_slice where you're still going "forward" but a negative offset starts you X entries from the end, I don't believe there's a direct comparison.
The goal was to work with the preceding chanel entry on the same page as the current channel entry.
I managed to do it instead by pulling out the relevant entry_ids and processing them in php and then put them back in with a fixed_order attribute