I was not expecting to get back a value from the query below. 1574208000#W2 is not between 1574207999 and 1574208001. But the records are still returned. Can anyone shed light on how the between comparison is done?
DynamoDb between operator with strings works with the lexicographic order of the strings (ie, the order in which they would appear in a dictionary). Using this order, 1574208000#W2 does fall between 1574207999 and 1574208001
Two strings are lexicographically equal if they are the same length and contain the same characters in the same positions.
Apart from that, to determine which string comes first, compare corresponding characters of the two strings from left to right. The first character where the two strings differ determines which string comes first. Characters are compared using the Unicode character set. All uppercase letters come before lower case letters. If two letters are the same case, then alphabetic order is used to compare them.
If two strings contain the same characters in the same positions, then the shortest string comes first. Ref
To try this out, you can try a simple example in Java
String a = "1574207999", b = "1574208000#W2", c = "1574208001";
System.out.println(a.compareTo(b)); // prints negative number, indicating a < b
System.out.println(b.compareTo(c)); // prints negative number, indicating b < c
Related
Using R, I need to create a vector and in all even numbers. The numbers displayed must be in ascending order.
Find near duplicate string. Hi, I know there is a match, unique, duplicated function in R, but none of these does wha I'm really need. I've a unique column in my dataset that I need to go trough it to check if the number are nearly the same. For instance, the first element compared with the second has nearly equal pattern, except for the number '9'. The second compared with the third is nearly equal, except for the last number o the sequence, one is ending with 6 while other ending with 5. Lastly, the two last numbers are 100% equal. If I've used unique() function, only the last case would be correctly excluded.
I'm wondering if there is a function that I can flag nearly equal, maybe calculating the percentage of equality, so I can drive my attention to those cases with highly equality rate.
dat <- data.frame(text = c("87775956",
"987775956",
"987775955",
"987481732",
"987481732"))
I would like to be able to control the hierarchy of elements I extract from a search string.
Specifically, in the string "425 million won", I would like to extract "won" first, but then "n" if "won" doesn't appear.
I want the result to be "won" for the following:
stringr::str_extract("425 million won", "won|n")
Note that specifying a space before won in my regex is inadequate because of other limitations in my data (there may not necessarily be a space between "million" and "won"). Ideally, I would like to do this using regex, as opposed to if-else clauses because of performance considerations.
See code in use here
pattern <- "^(?:(?!won).)*\\K(?:won|n)"
s <- "425 million won"
m <- gregexpr(pattern,s,perl=TRUE)
regmatches(s,m)[[1]]
Explanation
^ Assert position at the start of the line
(?:(?!won).)* Tempered greedy token matching any character except instances where won proceeds
\K Resets the starting point of the match. Any previously consumed characters are no longer included in the final match
(?:won|n) Match either won or n
If you just want to extend on the code you already have:
na.omit(str_extract("420 million won", c("won", "n")))[1]
I need to compare two hex values in drools.
for eg: compare 0xbadf00d with 0xbadf00e
This should result in false as d doesn't match with e.
So my question is, can hex be treated as string value and same comparisons can be made, or there is some other way.
I tried googling but no use.
When using ASCII, the natural order of the digits and letters of an HEX is ascending. This makes the comparison of these values as Strings trivial (assuming they are left-padded with 0s and using the same case).
As an example, if you have an Input class with a hex attribute of type String you can write something like this:
rule "Test"
when
$i1: Input()
$i2: Input(hex > $i1.hex)
then
//Do whatever you need here
end
Hope it helps,
What is the logic used by R to end up with the output FALSE in the below logical operation on characters. Is it just comparing letter S with letter T instead of the entire string.
"Sachin" > "Tendulkar"
Output: FALSE
This is in the documentation. ?">" gives:
Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use
In other words, this is just a regular dictionary-style comparison. Things can get very complicated/weird depending on locales (e.g. how non-alphabetic, accented, upper/vs lower case, etc. etc. characters are handled), but this case looks straightforward. "S" comes before "T" in every locale I can imagine, so "S"<"T"; in a lexicographic sort, this will determine the order (otherwise ties would be broken by later letters in the sequence).