by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Per-Åke Minborg
    @minborg
    ok. Not 100% sure but I suspect you can use different classes for the applications. So for example you have two Speedment web projects beans with Project1Application and Project2Application.
    If you are using the exact same Speedment model but have two different projects, it is possible to create a “holder” class for each of those apps. E.g. class Project1Application extends MyApplication and class Project2Application extends MyApplication
    Emil Forslund
    @Pyknic
    @java-coders The easiest way would be to name them in the Spring @Bean("") annotation. See a non-Speedment example on how to do it here.
    java-coders
    @java-coders
    @Pyknic It would not work because @Bean("") annotation exist in Generated..Configuration class which will be removed during regeneration of speedment project using speedment:tool
    java-coders
    @java-coders
    @minborg I am using two different speedment model for two different schema in single springboot project . Application class name is different for two project one is class Project1Application extends GeneratedProject1Application and another is class Project2Application extends GeneratedProject2Application . I have two different configuration class one is class Project1Configuration extends GeneratedProject1Configuration and another is class Project2Configuration extends GeneratedProject2Configuration . Now in each Generated.. Configuration class I have getApplication () method which is conflicting in springboot web project where I have used the speedment model.
    Emil Forslund
    @Pyknic
    @java-coders Does it work to simply merge the two speedment.json-files (put both the schemas into the same schemas-array) and generate a single ProjectApplication-class?
    solangepaz
    @solangepaz

    How can I apply a filter after a join?
    I have this

      JoinComponent joinComponent = app.getOrThrow(JoinComponent.class);
            Join<Tuple2<Lineorder, Date>> join = joinComponent
                    .from(LineorderManager.IDENTIFIER)
                    .innerJoinOn(Date.D_DATEKEY).equal(Lineorder.LO_CUSTKEY)
                    .build(Tuples::of);

    but I can not do join.stream (). filter()

    The query I want to do is this
    SELECT sum(lo_extendedprice*lo_discount) as revenue
    FROM lineorder lo, date d
    WHERE lo_orderdate = d_datekey
    AND d_year = 1993
    AND lo_discount between 1 and 3
    AND lo_quantity < 25;
    Per-Åke Minborg
    @minborg
    Hi @solangepaz . You can apply a .where()peredicate to a table that is joined and filter out data directly from the source.
    e.g.
      JoinComponent joinComponent = app.getOrThrow(JoinComponent.class);
            Join<Tuple2<Lineorder, Date>> join = joinComponent
                    .from(LineorderManager.IDENTIFIER).where(Lineorder.BETWEEN(1, 3))
                    .innerJoinOn(Date.D_DATEKEY).equal(Lineorder.LO_CUSTKEY)
                    .build(Tuples::of);
    solangepaz
    @solangepaz
    Thank you :)
    solangepaz
    @solangepaz
    And how can I apply group by () and order by () in this query? I'm not able to join.stream (). Collect (groupingBy ())
    Join<Tuple5<Lineorder, Customer, Supplier, Part, Date>> join = joinComponent
                    .from(LineorderManager.IDENTIFIER)
                    .innerJoinOn(Customer.C_CUSTKEY).equal(Lineorder.LO_CUSTKEY)
                    .where(Customer.C_REGION.equal("AMERICA"))
                    .innerJoinOn(Supplier.S_SUPPKEY).equal(Lineorder.LO_SUPPKEY)
                    .where(Supplier.S_REGION.equal("AMERICA"))
                    .innerJoinOn(Part.P_PARTKEY).equal(Lineorder.LO_PARTKEY)
                    .where(Part.P_MFGR.equal("MFGR#1").or(Part.P_MFGR.equal("MFGR#2")))
                    .innerJoinOn(Date.D_DATEKEY).equal(Lineorder.LO_ORDERDATE)
                    .build(Tuples::of);
    
    
    SELECT d_year, c_nation, sum(lo_revenue - lo_supplycost) as profit
    FROM date d, customer c, supplier s, part p, lineorder lo
    WHERE lo_custkey = c_custkey
    AND lo_suppkey = s_suppkey
    AND lo_partkey = p_partkey
    AND lo_orderdate = d_datekey
    AND c_region = 'AMERICA'
    AND s_region = 'AMERICA'
    AND (p_mfgr = 'MFGR#1' or p_mfgr = 'MFGR#2')
    GROUP BY d_year, c_nation
    ORDER BY d_year, c_nation;
    Per-Åke Minborg
    @minborg
    Take a look att the Aggregator (if you are using ‘free’) https://speedment.github.io/speedment-doc/aggregations.html#top
    Why are you unable to use collect(groupingBy()) ?
    solangepaz
    @solangepaz

    I can have this:

       JoinComponent joinComponent = app.getOrThrow(JoinComponent.class);
    
    
            Join<Tuple5<Lineorder, Customer, Supplier, Part, Date>> join = joinComponent
                    .from(LineorderManager.IDENTIFIER)
                    .innerJoinOn(Customer.C_CUSTKEY).equal(Lineorder.LO_CUSTKEY)
                    .where(Customer.C_REGION.equal("AMERICA"))
                    .innerJoinOn(Supplier.S_SUPPKEY).equal(Lineorder.LO_SUPPKEY)
                    .where(Supplier.S_REGION.equal("AMERICA"))
                    .innerJoinOn(Part.P_PARTKEY).equal(Lineorder.LO_PARTKEY)
                    .where(Part.P_MFGR.equal("MFGR#1").or(Part.P_MFGR.equal("MFGR#2")))
                    .innerJoinOn(Date.D_DATEKEY).equal(Lineorder.LO_ORDERDATE)
                    .build(Tuples::of);
    
    Map<Integer, List<Tuple5<Lineorder, Customer, Supplier, Part, Date>>> result = join.stream().collect(groupingBy(t ->t.get4().getDYear()));

    How do I apply the other group by and order by?

    solangepaz
    @solangepaz
    image.png
    I should get a result like this
    Per-Åke Minborg
    @minborg
    One idea is to use Tuples for the groupingBy(). This is an interesing question from a principal point of view. Give me some time to come up with an example.
    Per-Åke Minborg
    @minborg
    I have added an example of a similar case in the manual now: https://speedment.github.io/speedment-doc/speedment_examples.html#join-group-by-and-order-by
    Let me know if this fixes the problem @solangepaz
    solangepaz
    @solangepaz
    image.png
    I do not have the t.get option
    Per-Åke Minborg
    @minborg
    This is a problem related to Java’s type inference. Try explicitly declaring the type of t while you are experimenting.
    solangepaz
    @solangepaz
    Thank you, this worked :)
    solangepaz
    @solangepaz
    How can I convert this query to stream?
    SELECT
         l_returnflag,
         l_linestatus,
         sum (l_quantity) sum_qty,
         sum (l_extendedprice) sum_base_price,
         sum (l_extendedprice * (1 - l_discount)) sum_disc_price,
         sum (l_extendedprice * (1 - l_discount) * (1 + l_tax)) sum_charge,
         avg (l_quantity) as avg_qty,
         avg (l_extendedprice) as avg_price,
         avg (l_discount) as avg_disc,
         count (*) as count_order
    FROM
         lineitem
    ONDE
         l_shipdate <= date '1998-12-01' - interval '90' day
    GROUP BY
         l_returnflag,
         l_linestatus
    ORDER BY
         l_returnflag,
         l_linestatus;
    I have it only:
            LineitemManager lineitem = app.getOrThrow(LineitemManager.class);
            lineitem
                   .stream()
                   .filter(Lineitem.L_SHIPDATE.lessOrEqual(sqlDate))
                   .sorted(Lineitem.L_RETURNFLAG)
                   .sorted(Lineitem.L_LINESTATUS)
    Per-Åke Minborg
    @minborg
    @solangepaz Which Speedment version are you using? I would use the aggregator for this problem (requires “free” or “enterprise”)
    raghav-chamarthy
    @raghav-chamarthy
    Hey guys, we have an application that reads XML data, parses it using JAXB, does some transformation and validation and writes it to dynamo DB.
    The problem is we need to write custom code to onboard every new entity , and that makes us slow, can I use speedment to generate auto mapper code or any other open source library?? Thank you
    Per-Åke Minborg
    @minborg
    Yes you can. Speedment can generate standard SQL code and also you can plug in your own code generators. Contact me at minborg@speedment.com and I can tell you more.
    solangepaz
    @solangepaz
    @minborg, I am using the opensource version, so this query can not reproduce?
    Per-Åke Minborg
    @minborg
    You can but it is a bit tricky. You can create a stream over the line items and then apply collect(groupingBy(…)))
    You can create a custom “down stream collector” that does all the avg(), sum() etc.
    There is an open issue for creating these queries in an easier way.
    solangepaz
    @solangepaz
    @minborg Thank you. And is this query possible?
    select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment from PART, SUPPLIER, PARTSUPP, NATION, REGION 
    where p_partkey = ps_partkey 
    and s_suppkey = ps_suppkey 
    and p_size = 30 
    and p_type like '%STEEL' 
    and s_nationkey = n_nationkey 
    and n_regionkey = r_regionkey 
    and r_name = 'ASIA' 
    and ps_supplycost
     = (select min(ps_supplycost) from PARTSUPP, SUPPLIER, NATION, REGION 
     where p_partkey = ps_partkey 
     and s_suppkey = ps_suppkey 
     and s_nationkey = n_nationkey 
     and n_regionkey = r_regionkey 
     and r_name = 'ASIA')
     order by s_acctbal desc, n_name, s_name, p_partkey limit 100;
    I already have this
     JoinComponent joinComponent = app.getOrThrow(JoinComponent.class);
            Join<Tuple5<Partsupp, Part, Supplier, Nation, Region>> join = joinComponent
                    .from(PartsuppManager.IDENTIFIER)
                    .where(Partsupp.PS_SUPPLYCOST.equal())
                    .innerJoinOn(Part.P_PARTKEY).equal(Partsupp.PS_PARTKEY)
                    .where(Part.P_SIZE.equal(30).and(Part.P_TYPE.endsWith("STEEL")))
                    .innerJoinOn(Supplier.S_SUPPKEY).equal(Partsupp.PS_SUPPKEY)
                    .innerJoinOn(Nation.N_NATIONKEY).equal(Supplier.S_NATIONKEY)
                    .innerJoinOn(Region.R_REGIONKEY).equal(Nation.N_REGIONKEY)
                    .where(Region.R_NAME.equal("ASIA"))
                    .build(Tuples::of);
    But I can not do the subquery
    Per-Åke Minborg
    @minborg
    I suggest that you do the sub query first and store the min value in a separate variable. This vaiable is then used in a where clause.
    solangepaz
    @solangepaz

    Thank you. And how do I get this query?

    SELECT avg (l_quantity) as avg_qty
    FROM
         lineitem
    ONDE
         l_shipdate <= date '1998-12-01' - interval '90' day
    GROUP BY
         l_returnflag,
         l_linestatus;

    I already have this, but I can not return to the average:

    
            LineitemManager lineitem = app.getOrThrow(LineitemManager.class);
            Map<Tuple2<String, String>, Long> grouped = lineitem.stream().filter(Lineitem.L_SHIPDATE.lessOrEqual(sqlDate))
                    .collect(groupingBy(t->Tuples.of(t.getLReturnflag(), t.getLLinestatus()), ));
    
    
            grouped.forEach((k, v) -> {
                System.out.format("%-32s, %,d%n", k, v);
            });
    solangepaz
    @solangepaz
    I've tried this, but it can not. Because the values I want to get as average are not recognized
    Per-Åke Minborg
    @minborg
    What type is returned by getLQuantity() ?
    solangepaz
    @solangepaz
    BigDecimal
    Per-Åke Minborg
    @minborg
    Ahhh. Ok.
    Have you tried something like: Collectors.averagingDouble(t -> t.getLQuantity().doubleValue())
    solangepaz
    @solangepaz
    It worked, thank you :)
    Per-Åke Minborg
    @minborg
    Great!
    solangepaz
    @solangepaz
    Another question, is this part possible to implement?
    sum (case
             when o_orderpriority = '1-URGENT'
                 OR o_orderpriority = '2-HIGH'
                 then 1
             else 0
         end) the high_line_count,
         sum (case
             when o_orderpriority <> '1-URGENT'
                 AND o_orderpriority <> '2-HIGH'
                 then 1
             else 0
         end) AS low_line_count
    Per-Åke Minborg
    @minborg
    They appear to be each others' inverse logic.