Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[function] support EXTRACT #428

Closed
BohuTANG opened this issue Apr 28, 2021 · 4 comments · Fixed by #4329
Closed

[function] support EXTRACT #428

BohuTANG opened this issue Apr 28, 2021 · 4 comments · Fixed by #4329
Assignees
Labels
A-query Area: databend query C-feature Category: feature community-take good first issue Category: good first issue prio: normal Medium priority

Comments

@BohuTANG
Copy link
Member

BohuTANG commented Apr 28, 2021

Summary
Extract parts from a given date.

SELECT EXTRACT(DAY FROM toDate('2017-06-15'));
SELECT EXTRACT(MONTH FROM toDate('2017-06-15'));
SELECT EXTRACT(YEAR FROM toDate('2017-06-15'));

https://clickhouse.tech/docs/en/sql-reference/operators/#operator-extract

EXTRACT function used in TPC-H tests Q7:

select
    supp_nation,
    cust_nation,
    l_year,
    sum(volume) as revenue
from
    (
        select
            n1.n_name as supp_nation,
            n2.n_name as cust_nation,
            extract(year from l_shipdate) as l_year,
            l_extendedprice * (1 - l_discount) as volume
        from
            supplier,
            lineitem,
            orders,
            customer,
            nation n1,
            nation n2
        where
                s_suppkey = l_suppkey
          and o_orderkey = l_orderkey
          and c_custkey = o_custkey
          and s_nationkey = n1.n_nationkey
          and c_nationkey = n2.n_nationkey
          and (
                (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
                or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
            )
          and l_shipdate between date '1995-01-01' and date '1996-12-31'
    ) as shipping
group by
    supp_nation,
    cust_nation,
    l_year
order by
    supp_nation,
    cust_nation,
    l_year;
@BohuTANG BohuTANG added C-feature Category: feature prio: high High priority A-query Area: databend query SQL prio: normal Medium priority and removed prio: high High priority labels Apr 28, 2021
@BohuTANG BohuTANG changed the title Support extract [function] support extract Jun 9, 2021
@BohuTANG BohuTANG changed the title [function] support extract [function] support EXTRACT Jun 9, 2021
@BohuTANG BohuTANG added this to the v0.5 milestone Jun 22, 2021
@BohuTANG BohuTANG added the good first issue Category: good first issue label Sep 3, 2021
@GrapeBaBa
Copy link
Contributor

Is it an easy task?

@sundy-li
Copy link
Member

sundy-li commented Sep 6, 2021

it's already covered in #853

extract(year from l_shipdate) as l_year, --> toYear(l_shipdate)

@BohuTANG
Copy link
Member Author

BohuTANG commented Oct 11, 2021

it's already covered in #853

extract(year from l_shipdate) as l_year, --> toYear(l_shipdate)

Perhaps we should have a alias to to<Year|Month|Day> for the extract.

@BohuTANG BohuTANG removed the SQL label Oct 16, 2021
@BohuTANG BohuTANG removed this from the v0.5 milestone Oct 29, 2021
@clark1013
Copy link
Contributor

/assignme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query Area: databend query C-feature Category: feature community-take good first issue Category: good first issue prio: normal Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants