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;
}







0















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?










share|improve this question


















  • 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


















0















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?










share|improve this question


















  • 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














0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












2 Answers
2






active

oldest

votes


















1














This should work SELECT cast(Abs(-243.5) as float) AS AbsNum






share|improve this answer































    0














    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.






    share|improve this answer


























    • What is different between this and what I have?

      – Taylrl
      Nov 16 '18 at 11:48












    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    This should work SELECT cast(Abs(-243.5) as float) AS AbsNum






    share|improve this answer




























      1














      This should work SELECT cast(Abs(-243.5) as float) AS AbsNum






      share|improve this answer


























        1












        1








        1







        This should work SELECT cast(Abs(-243.5) as float) AS AbsNum






        share|improve this answer













        This should work SELECT cast(Abs(-243.5) as float) AS AbsNum







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 12:15









        JonToutJonTout

        381110




        381110

























            0














            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.






            share|improve this answer


























            • What is different between this and what I have?

              – Taylrl
              Nov 16 '18 at 11:48
















            0














            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.






            share|improve this answer


























            • What is different between this and what I have?

              – Taylrl
              Nov 16 '18 at 11:48














            0












            0








            0







            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.






            share|improve this answer















            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.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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



















            • 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


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues