5 Replies Latest reply: Apr 24, 2013 11:53 AM by John Lifter RSS

    Siyntax error Lua

      I'm fistly tried to wrote lua function for transformation 1 row to many.

      I testing this part of script:

      output = {}

         for columname,v in string.gmatch(input,"(%w+)=(%w+)") do

       

         output[columname]=v

       

       

         end

      On my Ubuntu, where i'm install Lua 5.1.4 , it works.

      But when i copy it to function :

       

      function transform(input)

       

         output = {}

         for columname,v in string.gmatch(input,"(%w+)=(%w+)") do

       

         output[columname]=v

       

       

         end

       

         return output;

       

      end;

      Expressor return me an error :

       

       

      Write Excel 1 - RULE_DESCRIPTOR-0020-A: The datascript rule 'Rule Write Custom' failed Datascript initialization. There is probably Datascript syntax error. (testdataflow.Step_1)

      Write Excel 1 - LUA_HELPERS-0018-A: Error LUA_ERRSYNTAX initializing Datascript: 'Rule Write Custom:113: unexpected symbol near 'end''. (testdataflow.Step_1)

      Help me to undestand? that i doing wrong(

       


        • Re: Siyntax error Lua

          To reply completely, we would need to see an example of your input data and a screen shot of the transform operator rule editor.  We need to see what attributes you have within the Input and Output panels.

           

          However, there are a couple of issues with your attempt to test using Lua and then transfer into Expressor.

          1. Yes, with just Lua this would work as the table output would contain multiple entries as anticipated.
            • But this is not directly transferable to Expressor.
          2. In the transform function, the first argument to gmatch must specify an input attribute.  That is, input is not correct; it needs to be input.<some attribute name>.
            • This is why we must see representative data and the screen shot of the rule editor.
          3. In the transform function, the for loop will initialize the output table with the multiple entries, but the return statement will only work if there are an equivalent number of identically named output attributes.
            • Again, this is why we must see the screen shot of the rule editor.
          4. If you want the transform operator to emit multiple records for each input record, you will need to use the iterative return approach (see http://community.qlik.com/docs/DOC-3251).

           

           

          Please provide representative data and the rule editor screen shot.

          • Re: Siyntax error Lua

            Код в Expressor.JPG

            field 8 is string folowing format " fieldname1=value fieldname2=value..."

              • Re: Siyntax error Lua

                In line 4, the first argument to gmatch should be input.field8, not just input.

                  • Re: Siyntax error Lua

                    I'm change toinput.field8 but error still where.

                      • Re: Siyntax error Lua

                        I'm not having difficulties duplicating your objective.

                         

                        Note that I used string.iterate instead of string.gmatch, but there is no difference.  string.gmatch was renamed to string.iterate in Expressor.

                         

                        My input file contains one line with the following content.

                        field1=hello field2=goodbye field3=3

                         

                        I read this input file with a delimited schema in which the field delimiter is the comma and the record delimiter is \r\n.  Therefore, each line is contained in a single field, which I call 'line.'

                         

                        In the transform, I use your code exactly, blocking the input attribute and initializing one attribute for each field entry.  See the following figure.

                         

                        Then, I write the record to an Excel file.

                         

                        syntax.png