Code Monkey home page Code Monkey logo

Comments (3)

torrmal avatar torrmal commented on June 26, 2024

thank you @bobcolner,

Would you like to help us with the documentation?
@btseytlin can show you the ropes of whats supported from SQL.

from dfsql.

btseytlin avatar btseytlin commented on June 26, 2024

@bobcolner Thanks!
Here's the currently supported list of functions:

OPERATIONS = (
    And, Or, Not,

    Equals, NotEquals, Greater, GreaterEqual, Less, LessEqual, Is, IsNot,

    Plus, Minus, Multiply, Divide, Modulo, Power,

    StringConcat, StringLower, StringUpper, Like,

    In,
)
AGGREGATE_FUNCTIONS = (
    Sum, Mean, Count, CountDistinct,
)

You can also make your own functions, similar to how you can do pd.DataFrame().apply(my_function) or pd.DataFrame().agg({column: my_function}).
E.g.:

def custom(x):
    return x + '_custom_addition'

data_source.register_function('custom', custom)
sql = "SELECT custom(\"a\")"
query_result = data_source.query(sql)
assert query_result == 'a_custom_addition'

Or alternatively, you can pass custom functions to sql_query:

from dfsql import sql_query

sql_query('SELECT magic_function(column1) FROM df', df=df, custom_functions={'magic_function': lambda x: x*x})

See these tests for examples:
https://github.com/mindsdb/dfsql/blob/stable/tests/test_data_sources/test_file_data_source.py#L342
https://github.com/mindsdb/dfsql/blob/stable/tests/test_data_sources/test_file_data_source.py#L712

from dfsql.

bobcolner avatar bobcolner commented on June 26, 2024

thanks!

from dfsql.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.