Nifi: Can I do mathematical operations on a json file values?










0















I have a JSON file as an input to a processor. Something like this:



"x" : 10, "y" : 5


Can I do mathematical operations on these values instead of writing a custom processor? I need to do something like



( x / y ) * 3


^ Just an example.



I need to save the result to an output file.



UPDATE:
This is my text in generateFlowFile processor:



X|Y
1|123
2|111


And this is my AVRO schema:




"name": "myschema",
"namespace": "nifi",
"type": "record",
"fields": [
"name": "X" , "type": "int",
"name": "Y" , "type": "int" ]



When I change the above types to string, it works fine but I cannot perform math operations on a string.



FYI, I have selected 'Use Schema Name Property' in Schema Access Strategy










share|improve this question




























    0















    I have a JSON file as an input to a processor. Something like this:



    "x" : 10, "y" : 5


    Can I do mathematical operations on these values instead of writing a custom processor? I need to do something like



    ( x / y ) * 3


    ^ Just an example.



    I need to save the result to an output file.



    UPDATE:
    This is my text in generateFlowFile processor:



    X|Y
    1|123
    2|111


    And this is my AVRO schema:




    "name": "myschema",
    "namespace": "nifi",
    "type": "record",
    "fields": [
    "name": "X" , "type": "int",
    "name": "Y" , "type": "int" ]



    When I change the above types to string, it works fine but I cannot perform math operations on a string.



    FYI, I have selected 'Use Schema Name Property' in Schema Access Strategy










    share|improve this question


























      0












      0








      0








      I have a JSON file as an input to a processor. Something like this:



      "x" : 10, "y" : 5


      Can I do mathematical operations on these values instead of writing a custom processor? I need to do something like



      ( x / y ) * 3


      ^ Just an example.



      I need to save the result to an output file.



      UPDATE:
      This is my text in generateFlowFile processor:



      X|Y
      1|123
      2|111


      And this is my AVRO schema:




      "name": "myschema",
      "namespace": "nifi",
      "type": "record",
      "fields": [
      "name": "X" , "type": "int",
      "name": "Y" , "type": "int" ]



      When I change the above types to string, it works fine but I cannot perform math operations on a string.



      FYI, I have selected 'Use Schema Name Property' in Schema Access Strategy










      share|improve this question
















      I have a JSON file as an input to a processor. Something like this:



      "x" : 10, "y" : 5


      Can I do mathematical operations on these values instead of writing a custom processor? I need to do something like



      ( x / y ) * 3


      ^ Just an example.



      I need to save the result to an output file.



      UPDATE:
      This is my text in generateFlowFile processor:



      X|Y
      1|123
      2|111


      And this is my AVRO schema:




      "name": "myschema",
      "namespace": "nifi",
      "type": "record",
      "fields": [
      "name": "X" , "type": "int",
      "name": "Y" , "type": "int" ]



      When I change the above types to string, it works fine but I cannot perform math operations on a string.



      FYI, I have selected 'Use Schema Name Property' in Schema Access Strategy







      apache-nifi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 18:48







      NoName

















      asked Nov 15 '18 at 0:26









      NoNameNoName

      3081418




      3081418






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Use QueryRecord processor.



          • Configure/enable Record Reader/Writer controller services

          • Define Avro schema to read the incoming Json.

          • Define Avro Schema to write the results of query in desired format.

          Add new property in the query record processor as



          sql



          select ( x / y ) * 3 as div from FLOWFILE


          The output flowfile from the query record processor will be in the configured Record Writer format.






          share|improve this answer























          • Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

            – NoName
            Nov 17 '18 at 0:11











          • @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

            – Shu
            Nov 19 '18 at 14:41











          • I updated the question. Please take a look

            – NoName
            Nov 19 '18 at 18:48












          • @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

            – Shu
            Nov 19 '18 at 20:07










          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%2f53310774%2fnifi-can-i-do-mathematical-operations-on-a-json-file-values%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Use QueryRecord processor.



          • Configure/enable Record Reader/Writer controller services

          • Define Avro schema to read the incoming Json.

          • Define Avro Schema to write the results of query in desired format.

          Add new property in the query record processor as



          sql



          select ( x / y ) * 3 as div from FLOWFILE


          The output flowfile from the query record processor will be in the configured Record Writer format.






          share|improve this answer























          • Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

            – NoName
            Nov 17 '18 at 0:11











          • @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

            – Shu
            Nov 19 '18 at 14:41











          • I updated the question. Please take a look

            – NoName
            Nov 19 '18 at 18:48












          • @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

            – Shu
            Nov 19 '18 at 20:07















          1














          Use QueryRecord processor.



          • Configure/enable Record Reader/Writer controller services

          • Define Avro schema to read the incoming Json.

          • Define Avro Schema to write the results of query in desired format.

          Add new property in the query record processor as



          sql



          select ( x / y ) * 3 as div from FLOWFILE


          The output flowfile from the query record processor will be in the configured Record Writer format.






          share|improve this answer























          • Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

            – NoName
            Nov 17 '18 at 0:11











          • @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

            – Shu
            Nov 19 '18 at 14:41











          • I updated the question. Please take a look

            – NoName
            Nov 19 '18 at 18:48












          • @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

            – Shu
            Nov 19 '18 at 20:07













          1












          1








          1







          Use QueryRecord processor.



          • Configure/enable Record Reader/Writer controller services

          • Define Avro schema to read the incoming Json.

          • Define Avro Schema to write the results of query in desired format.

          Add new property in the query record processor as



          sql



          select ( x / y ) * 3 as div from FLOWFILE


          The output flowfile from the query record processor will be in the configured Record Writer format.






          share|improve this answer













          Use QueryRecord processor.



          • Configure/enable Record Reader/Writer controller services

          • Define Avro schema to read the incoming Json.

          • Define Avro Schema to write the results of query in desired format.

          Add new property in the query record processor as



          sql



          select ( x / y ) * 3 as div from FLOWFILE


          The output flowfile from the query record processor will be in the configured Record Writer format.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 1:08









          ShuShu

          4,7912418




          4,7912418












          • Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

            – NoName
            Nov 17 '18 at 0:11











          • @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

            – Shu
            Nov 19 '18 at 14:41











          • I updated the question. Please take a look

            – NoName
            Nov 19 '18 at 18:48












          • @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

            – Shu
            Nov 19 '18 at 20:07

















          • Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

            – NoName
            Nov 17 '18 at 0:11











          • @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

            – Shu
            Nov 19 '18 at 14:41











          • I updated the question. Please take a look

            – NoName
            Nov 19 '18 at 18:48












          • @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

            – Shu
            Nov 19 '18 at 20:07
















          Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

          – NoName
          Nov 17 '18 at 0:11





          Thank you for the answer! I tried the same but I get an error when the field type is "int" in the schema. Error is : Failed to read next record in input for 'x' due to For input string:'x'. And this is happening only for type int or long. But if I change to string and have the sql as selct * from FLOWFILE , it works fine.

          – NoName
          Nov 17 '18 at 0:11













          @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

          – Shu
          Nov 19 '18 at 14:41





          @NoName, I think the issue is coming with Avro Schema, please update your question with sample data and Reader/Writer Avro schema that you are using now. So that i will try to help u to fix the issue...!!

          – Shu
          Nov 19 '18 at 14:41













          I updated the question. Please take a look

          – NoName
          Nov 19 '18 at 18:48






          I updated the question. Please take a look

          – NoName
          Nov 19 '18 at 18:48














          @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

          – Shu
          Nov 19 '18 at 20:07





          @NoName, I tried with your sample records and uploaded template here: github.com/shureddy/NiFiTemplates/blob/master/… upload this template to your instance and change the avro schema as per your case.

          – Shu
          Nov 19 '18 at 20:07



















          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%2f53310774%2fnifi-can-i-do-mathematical-operations-on-a-json-file-values%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

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線