LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  SQL "in" function

    Employee
    Posted 01-16-2013 02:44

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Feridun

    Hello everybody,

    I am looking for a function, which is like "IN" in SQL. For instance, I would like to get the records that have Ids 3,4,5 in static data.

    what I'm writing:
    emit *
    where id==2 or id==4 or id==6

    What I would like to write

    emit *
    where id.function(2,4,6)

    Anybody knows how to do this?

    thank you

    Feridun


  • 2.  RE: SQL "in" function

    Employee
    Posted 01-16-2013 03:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Wizardous

    Hi Feridun

    I think you can use list function like i typed below.

    vlist=list(2,4,6)
    emit *
    where vlist.find(id)!=-1

    Take care

    Ozgun


  • 3.  RE: SQL "in" function

    Employee
    Posted 01-16-2013 03:25

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Feridun

    Hey Ozgun,

    The problem is, I will have to,then, create a list of 900 millions of items inside. will be a bit of trouble I guess to "find" within the list.

    Cheers

    Feridun


  • 4.  RE: SQL "in" function

    Employee
    Posted 01-16-2013 08:10

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    You say "have to create a list of 900m items"

    If these items (before making a list) are individual records then you should be using the LOOKUP node instead.


  • 5.  RE: SQL "in" function

    Employee
    Posted 01-18-2013 03:33

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Feridun

    Hi Stony,

    I mean, it depends on the business of course, what I'm doing now is as a workaround is creating a static data node with some codes (around 35) and creating a lookup as you say. but as I understand, there is no such a "in" function I guess.


  • 6.  RE: SQL "in" function

    Employee
    Posted 01-23-2013 07:51

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Feridun, I am not quite sure I understand your business need with the above discussion. While we don't specifically have an "in" function, the functionality exists in a number of ways, as described above (using the list and find approach, or the generally better lookup approach you are using). Is there a specific problem you haven't been able to solve in this way? It seems your question more focused on specifically the "in" function and syntax. If that's the case, it is true we don't have that exact statement, but hopefully you have a working answer as it seems to indicate above.

    It sounds like you have a working solution, and I just want to make sure you are all set.

    Cheers
    Rich


  • 7.  RE: SQL "in" function

    Employee
    Posted 01-24-2013 08:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Feridun

    Hi Rich,
    Thank you for answer, i was just wondering if there was such a function, as i am new to lavastorm, instead of writing many "or" statements. What exactly i need to do is, i want to put a 1/0 flag beside some ids. i have an id list of 150, within a data of 1,9 billions. instead of writing id==2 or id==3 or ..., i'd like to write in(2,3,...). Lkp works fine too, and i think the workload is pretty the same right? So no problem..
    Thank you again for your answer.

    Regards

    Feridun


  • 8.  RE: SQL "in" function

    Employee
    Posted 01-24-2013 08:57

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    The lookup function is really well suited for such functions & I think that is the best way for you to move forward.

    However, you still can also use the find function as Ozgun pointed out.
    I think there might have been some confusion on the way that could be used so thought I would try & clarify.

    You wouldn't need to have your billions of records in the list - rather, the lookup keys would be in the list - and you also wouldn't need to have a whole lot of if id==1 then, else if id ==2 statements.

    Rather, you would have something like:


    
    #Populate your list with all of the 150 ids you want to use - you would have to do something similar with your "in" function anyway...
    vlist=list(2,3,...)
    
    #Check if the "id" field in an input record is in the specified list
    flag = vlist.find('id') !=-1
    
    #NOTE the above is really almost exactly the same as what you are what you would want with the "in" function using: where 'id' in (2,3,....)
    
    
    #Now output the data, with the flag
    emit *
    emit flag as "Flag"
    
    So really, the code is very similar to what you would do using "in", and has the functionality that you want.
    Hope this clears up things a bit.

    Tim.


  • 9.  RE: SQL "in" function

    Employee
    Posted 01-24-2013 09:19

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Sorry, I don't want to beat a dead horse here, but just to follow on to Tim's post, he is absolutely right you can do that as above; but I want to emphasize that for what you are trying to do, the Lookup node is perfect and designed for that purpose. Additionally, I believe it to be superior to the "in" phrase mentioned above.

    If you use a Static Data node (if you have a limited number and they are fixed), and you can clearly list all the values in a Static Data node, and see them in the node or as the input to the Lookup Node, so easy to view and edit; or you can retrieve them from a DB or file or other ways if you have other means to gather them, which can lend itself to being more dynamic and "smart".

    I have attached a simple example to show how Lookup could be configured specifically as you describe, using 3 different syntaxs...You can choose any of the different ways I configured each of BooleanFlag, IntFlag1, or IntFlag2, depending on what your desired output (Boolean or Int) and your preference of BRAINscript.

    Cheers
    Rich
    Attachments:
    Example of Lookup with flag.brg


  • 10.  RE: SQL "in" function

    Employee
    Posted 01-28-2013 02:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Feridun

    Hi Rich, Tim,

    Thank you guys for your help. That's absolutely what I was doing using the lookup node with just a slight difference of bringing the key field to the Data, instead of the flag. The flaging within the lookup is perfect!

    Thanks again.

    Cheers,

    Feridun