Giter Club home page Giter Club logo

Comments (15)

rbock avatar rbock commented on July 22, 2024

Hi,

I haven't thought about this before, but it certainly sounds like a reasonable idea. Could you give it a try?

Best,

Roland

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

I'll try,but I'm sure I'll need help :)

Br, Z.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

OK, looking forward to it :-)

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

Hi.
I've started creating this script for postgres database. First thing that I have done is a SQL query to get all aggregate functions from database ( query with output avalible at https://gist.github.com/cszawisza/c8a8456396a87a5db012 )

As you can see, the list contains all functions with overloads. So basing on this output, script can deduce what kind of input/output arguments pairs can be used in those functions, and probably create a overloaded list in C++ code as well, but... Is this really useful? or should the script create templates with only basic type checking(is numeric, float, or text) instead?

And what about normal functions? I find only type for "aggregate_function" and not for "normal" one.

Br, Z.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Hi,

nice script :-)

I would create one template per function and use basic type checking. And you do not need to replace the aggregate_function node. The aggregate_function is basically just a tag to detect nested aggregates (which are not allowed).

Best,

Roland

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

Hi!
I edited my sql script a bit, it's available at http://sqlfiddle.com/#!15/31586/4/0 now it prints a agregated inputs and outputs off all functions with 'appropriate' argument types. Unfortunately it drops information about strings so, to mark multiple arg functions, I add a && characters between arguments.
e.g.
fun1(A); fun1(B) -> A,B
fun2( A, B ), fun2(A,C) -> A && B, A && C

Output from query is parsed by python script which decides what kind of arguments are used in functions, and so:

No arg -> void
boolean -> boolean
text (and date etc.) -> text
if function has int and real I take the "bigger" type ( bool < int < real )
if function takes numeric and text type then is 'anyelement' type

and output generated from query is avalible at https://paste.kde.org/phszwbqam

In this table I think I've got most of the needed information to create a function template.

Name of function
Type of function (aggregate, normal or window)
Information if function returns the same type as argument type.
Return type
Input types and overloads

Is there any other information that can be useful to me?

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Hi,

Looks good! Sounds like you have all information you need to produce sqlpp11-compatible template struct and functions with that.

The devil will be in the detail, I guess :-)

Best,

Roland

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

Hi!
I have not so much experience in C++ template meta programming, therefore I don't clearly understand your library, is there any chance that you provide me a commented version of one of your function?
What Is most interesting for me is how to handle functions with multiple inputs.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Hi,

I just updated the concat method and added a free function. It is not in the master yet, but in develop:

https://github.com/rbock/sqlpp11/blob/develop/include/sqlpp11/concat.h

If you take a closer look and compare it to other functions, e.g. max, you will realize that most of the code is actually boilerplate (adding value-types and names, or checking input types).

Don't worry, it is not nearly as hard as might look at first glance.

I can try to prepare some documentation later (probably not before the weekend). It would help if you had concrete questions, or a first function you tried to assemble yourself.

Best,

Roland

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

HI!
I tried to write some function generator code, but I stuck with some questions. I noticed that structure of functions (max, concat, avg) are different.
Max: template
Avg: template<typename Flag, typename Expr>
Concat: template<typename... Args>

So my first pair of questions is
shouldn't Max has a "typename flag" argument?
If aggregate functions are treated all the same, how to read "flag" argument in concat function?

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Hi,

Functions like avg have an optional flag DISTINCT. This does not really make a difference for max or min, which is why I did not code it. But it would be more consistent to add flag to max and min. Good catch!

Not sure why you would want a flag for concat?

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

I have no need for this flag in concat, the only reason is why I'm asking is to create as many common code for all functions as possible, so even if this flag is not used it can be present in the definition.

My main idea is to define all functions as variadic templates, and check the number of arguments in static_aserts in constructor just like in concat, but then i need Flags :)

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Personally, I would not try too hard to find one pattern that fits all. To turn strictly unary or binary functions into variadic templates and adding a parameter just for the sake of having the same template parameter list (and then preventing its use with static_assert) sounds a bit strange to me.

That being said, I would still try to find as few groups of similar functions as possible :-)

from sqlpp11.

cszawisza avatar cszawisza commented on July 22, 2024

When I was writing the generator I discovered that for me, now, it is a lot easier to create function code by hand then to create a parser for that. Due to this I decided to stop developing it by now, and try once again, when I'll get get familiar with your lib and c++ templates.
Sorry for the trouble, and thanks for help.
Br, Z.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

No worries. Once you feel more comfortable with the whole thing and want to give it another try, just let me know.

Best,

Roland

from sqlpp11.

Related Issues (20)

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.