AnalysisException: Syntax error in line 1: error when taking modulus of a value using abs() in Impala
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I want to take the modulus of a value when using Impala and I am aware of the abs()
function. When I use this however like such
select abs(value) from table
It returns a value that is rounded to the nearest integer. The documentation found here states that I need to define the numeric_type
. have tried this
select abs(float value) from table
but this gives me the following error
AnalysisException: Syntax error in line 1: ... abs(float value) from table ^ Encountered: FLOAT Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error
Any ideas how I set abs()
to return a float
?
sql floating-point impala
add a comment |
I want to take the modulus of a value when using Impala and I am aware of the abs()
function. When I use this however like such
select abs(value) from table
It returns a value that is rounded to the nearest integer. The documentation found here states that I need to define the numeric_type
. have tried this
select abs(float value) from table
but this gives me the following error
AnalysisException: Syntax error in line 1: ... abs(float value) from table ^ Encountered: FLOAT Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error
Any ideas how I set abs()
to return a float
?
sql floating-point impala
1
Does this work for you?SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17
add a comment |
I want to take the modulus of a value when using Impala and I am aware of the abs()
function. When I use this however like such
select abs(value) from table
It returns a value that is rounded to the nearest integer. The documentation found here states that I need to define the numeric_type
. have tried this
select abs(float value) from table
but this gives me the following error
AnalysisException: Syntax error in line 1: ... abs(float value) from table ^ Encountered: FLOAT Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error
Any ideas how I set abs()
to return a float
?
sql floating-point impala
I want to take the modulus of a value when using Impala and I am aware of the abs()
function. When I use this however like such
select abs(value) from table
It returns a value that is rounded to the nearest integer. The documentation found here states that I need to define the numeric_type
. have tried this
select abs(float value) from table
but this gives me the following error
AnalysisException: Syntax error in line 1: ... abs(float value) from table ^ Encountered: FLOAT Expected: ALL, CASE, CAST, DEFAULT, DISTINCT, EXISTS, FALSE, IF, INTERVAL, NOT, NULL, TRUNCATE, TRUE, IDENTIFIER CAUSED BY: Exception: Syntax error
Any ideas how I set abs()
to return a float
?
sql floating-point impala
sql floating-point impala
asked Nov 16 '18 at 11:41
TaylrlTaylrl
6922920
6922920
1
Does this work for you?SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17
add a comment |
1
Does this work for you?SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17
1
1
Does this work for you?
SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Does this work for you?
SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17
add a comment |
2 Answers
2
active
oldest
votes
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
add a comment |
I think you are misunderstanding the syntax. You call the function as abs(val)
. The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337169%2fanalysisexception-syntax-error-in-line-1-error-when-taking-modulus-of-a-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
add a comment |
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
add a comment |
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
This should work SELECT cast(Abs(-243.5) as float) AS AbsNum
answered Nov 16 '18 at 12:15
JonToutJonTout
381110
381110
add a comment |
add a comment |
I think you are misunderstanding the syntax. You call the function as abs(val)
. The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
add a comment |
I think you are misunderstanding the syntax. You call the function as abs(val)
. The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
add a comment |
I think you are misunderstanding the syntax. You call the function as abs(val)
. The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.
I think you are misunderstanding the syntax. You call the function as abs(val)
. The return type is the same as the input type. It should work on integers, decimals, and floats.
If you want a particular type being returned, then you need to pass in that type, perhaps casting to the specific type.
The documentation is:
abs(numeric_type a)
Purpose: Returns the absolute value of the argument.
Return type: Same as the input value
Admittedly, this does look like the type should be part of the function call. But it is really using a programming language-style declaration to show the types that are expected.
edited Nov 16 '18 at 12:38
answered Nov 16 '18 at 11:45
Gordon LinoffGordon Linoff
794k37318421
794k37318421
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
add a comment |
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
What is different between this and what I have?
– Taylrl
Nov 16 '18 at 11:48
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337169%2fanalysisexception-syntax-error-in-line-1-error-when-taking-modulus-of-a-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Does this work for you?
SELECT cast(Abs(-243.5) as float) AS AbsNum
– JonTout
Nov 16 '18 at 11:45
Yes this worked! Would you like to submit it as an actual answer?
– Taylrl
Nov 16 '18 at 12:14
Wasn't sure if Impala had any differences compared with ms sql, but added as an answer...
– JonTout
Nov 16 '18 at 12:17