In the link https://cwiki.apache.org/Hive/languagemanual-udf.html, it is clearly mentioned that A && B is same as A AND B. But when i tried to use && in one of my hive query, it was not working (I am using hive-0.9.0-cdh4.1.2).
Sample Input:
12 23
2 6
Table schema as test(a int, b int). When I performed SELECT CASE WHEN (a<10 && b<10) THEN a+b END FROM test;, I got an exception message saying "FAILED: ParseException line 1:24 cannot recognize input near '&' 'b' '<' in expression specification".
Expected Output :
NULL
8
But when I replaced && with AND, it gave correct result. I want to know why this happened. Any help much appreciated! Thanks in advance.
I had run into this issue sometime ago and tried to do some research which remained incomplete because of other things. But what I found was that this is some parsing related issue. To be precise, ANTLR is not able to provide suitable parser to parse this query.
You could probably try using the latest version of Hive which has an upgraded version of ANTLR. But i'm still not sure that it will work even with that. To be frank, I wonder if && and || have ever worked.
Related
I've looked at lots of examples for TRIM and REPLACE on the internet and for some reason I keep getting errors when I try.
I need to strip suffixes from my Netsuite item record names in a saved item search. There are three possible suffixes: -T, -D, -S. So I need to turn 24335-D into 24335, and 24335-S into 24335, and 24335-T into 24335.
Here's what I've tried and the errors I get:
Can you help me please? Note: I can't assume a specific character length of the starting string.
Use case: We already have a field on item records called Nickname with the suffixes stripped. But I've ran into cases where Nickname is incorrect compared to Name. Ex: Name is 24335-D but Nickname is 24331-D. I'm trying to build a saved search alert that tells me any time the Nickname does not equal suffix-stripped Name.
PS: is there anywhere I can pay for quick a la carte Netsuite saved search questions like this? I feel bad relying on free technical internet advice but I greatly appreciate any help you can give me!
You are including too much SQL - a formulae is like a single result field expression not a full statement so no FROM or AS. There is another place to set the result column/field name. One option here is Regex_replace().
REGEXP_REPLACE({name},'\-[TDS]$', '')
Regex meaning:
\- : a literal -
[TDS] : one of T D or S
$ : end of line/string
To compare fields a Formulae (Numeric) using a CASE statement can be useful as it makes it easy to compare the result to a number in a filter. A simple equal to 1 for example.
CASE WHEN {custitem_nickname} <> REGEXP_REPLACE({name},'\-[TDS]$', '') then 1 else 0 end
You are getting an error because TRIM can trim only one character : see oracle doc
https://docs.oracle.com/javadb/10.8.3.0/ref/rreftrimfunc.html (last example).
So try using something like this
TRIM(TRAILING '-' FROM TRIM(TRAILING 'D' FROM {entityid}))
And always keep in mind that saved searches are running as Oracle SQL queries so Oracle SQL documentation can help you understand how to use the available functions.
I'm having an issue matching regular expression in BigQuery. I have the following line of code that tries to identify user agents:
when regexp_contains((cs_user_agent), '^AppleCoreMedia\/1\.(.*)iPod') then "iOS App - iPod"
However, BigQuery doesn't seem to like escape sequences for some reason and I get this error that I can't figure out:
Syntax error: Illegal escape sequence: \/ at [4:63]
This code works fine in a regex validator I use, but BigQuery is unhappy with it and I can't figure out why. Thanks in advance for the help
Use regexp_contains((cs_user_agent), r'^AppleCoreMedia\/1\.(.*)iPod')
I want to update a row in a table for my project, I'm copying a syntax I saw somewhere else here however, I think my problem comes when I try updating where ApplicantID is equal to $_SESSION["ID"].
I get this error
Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\...\InsertPData.php on line 22
here is the php along side the SQL:
<?php
include_once'dbconnect.php';
session_start();
function INSERT()
{
$Name=$_POST['name'];
$Relation=$_POST['Relation'];
$Email=$_POST['Email'];
$Address=$_POST['Address'];
$Postcode=$_POST['Postcode'];
$Mobile_Number=$_POST['Mobile_Number'];
$Home_Number=$_POST['Home_Number'];
$INSERT="UPDATE Applicants
SET ParentName='$Name',
Relationtoapplicant='$Relation',
ParentEmail='$Email',
ParentAddress='$Address',
ParentPostcode='$Postcode',
ParentMobile='$Mobile_Number',
ParentHome='$Home_Number',
WHERE ApplicantID=$_SESSION["ID"] "; #THIS IS LINE 22
$data=mysql_query($INSERT) or die(mysql_error());
if($data)
{
echo "Parents/Gauridan details hav been entered";
}
else print "error";
}
INSERT()
?>
I've already searched for a solution to this but haven't found something where the user is using a session thing. Thank you.
This is why an IDE with syntax highlighting is helpful. StackOverflow uses syntax highlighting on code blocks as well and actually already gives you the answer based on your code:
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION["ID"] ";
See how ID is suddenly black instead of dark red? That's because you are terminating the string there. The double quotes should either be escaped or replaced with single quotes, like:
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION[\"ID\"] ";
Or
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION['ID'] ";
See how the ID bit stays dark red? This is because now your string is not suddenly terminated.
Also, please do not use mysql_ functions anymore. They have been deprecated since 2013 and are currently not even a part of PHP anymore. So if you'd update your PHP to the latest version, this code would not work. On top of that, this code is vulnerable to SQL injection attacks.
Also see Why shouldn't I use mysql_* functions in PHP? and How can I prevent SQL-injection in PHP?.
I'm working with Google Big Query and try to extract some information from a string column into another column using Regexp_extract. In short:
Data in myVariable:
yippie/eggs-spam/?portlet:hungry=1234
yippie/eggs-spam/?portlet:hungry=456&portlet:hungrier=7890
I want a column with:
1234
456
My command:
SELECT Regexp_extract(myVariable, r'SOME_MAGIC') as result
FROM table
I tried for SOME_MAGIC:
hungry=(.*)[&$] - null, 456 (I learned that $ is interpreted as is)
hungry=(.*)(&|$) - Error: Exactly one capturing group must be specified
hungry=(.*)^& - null, null
hungry=(&.*)?$ - null, null
I read this, but there the number has a fixed length. Also looked at this, but "?=" is no known command for perl.
Does anybody have an idea? Thank you in advance!
I just found an answer to how I can solve my problem differently:
hungry=([0-9]+) - 1234, 456
It isn't an answer to my abstract question (regex for selecting Charater A to [Character B or EOL]), so it's not that satisfying. E.g. it won't work with
yippie/eggs-spam/?portlet:hungry=12AB34
However my original problem is solved. I leave the question open for a while in case somebody has a better answer.
I think I had a similar problem were I was trying to select the last 6 characters in a string (link_id) as a new column.
I kept getting this error:
Exactly one capturing group must be specified
My code originally was:
SELECT
...
REGEXP_EXTRACT(link_id, r'......$') AS updated_link_id
FROM sometable;
To get rid of the error and retrieve the correct substring as a column, I had to add parentheses around my regex string.
SELECT
...
REGEXP_EXTRACT(link_id, r'(......$)') AS updated_link_id
FROM sometable;
I'm trying to build a parser for a DSL I'm building using Irony in .NET and found a problem I can't find a way around. Since it handles BNF I think that any BNF solution will be of help.
I have the following input:
$10 yesterday at drug store
With the following grammar:
<expr> :== unit | expr + unit
<unit> :== money | date | location
<date> : == yesterday|today|tomorrow
<location> :== .* | <preposition> .*
<preposition> :== at
<money> :== ((\$)?\d*((\.*)\d*)*\,?\d{1,2})
It works like a charm with this input. I get exactly the result I wanted which is:
Money Amount: 10
Date: Yesterday
Location: Drug Store
However, if I change the order of the input as following
$10 at drug store yesterday
because of reduce steps it fails to give me the same output. The output becomes:
Money amount: 10
Location: Drug Store Yesterday
I was wondering if there is way to make sure that Location (which is a really broad regex match) is only evaluated when all the other tokens are captured and nothing else is left.
Any help is appreciated.
Thanks!
Edit: Updated title according to suggestion
Besides the fact that this is not a general answer to BNF ambiguity I was able to solve my problem with Irony by creating a new Terminal.
So if anyone else encounters this problem, the code for the new Terminal (while not added to main Irony project) can be found in this link: http://irony.codeplex.com/discussions/269483
Thanks