Code Monkey home page Code Monkey logo

Comments (1)

wewoor avatar wewoor commented on September 17, 2024

The Type of SQL
hive

Your Code

const { HiveSQL } = require('dt-sql-parser');
const parser = new HiveSQL();

const sql = `select 
from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd') as stat_date,
-- from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd HH:mm:ss') as stat_time,
'5' as track_type,
tenant_id,
-- 5  as track_type,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
count(DISTINCT uid_now) as now_cnt,
sum(case when uid_last is NULL then 0 else 1 end) as return_user_cnt 
from (select a.tenant_id,
        a.uid_now,
        b.uid_last 
from ( SELECT tenant_id ,
                user_id as uid_now 
        FROM tezign_dw.dw_fact_web_tracking_log_add_h
        where dt is not null
        and biz_line_id = 'd14eae7480b640cab48af3db8567d298' and product_line_id = '0358a581866642d9b8e6c1c94e5a5f00' AND is_page_flag =1 
        and cast(create_date as date) > DATE_ADD(from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd'),-7)
        and cast(create_date as date) <= from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd')
        and tenant_id not in ('t2', 't3', 't4', 't11', 't32', 't39', 't52', 't53', 't127', 't141', 't147', 't168', 't169', 't171',
           't172', 't173', 't174', 't178', 't187', 't192', 't197', 't199', 't202') 
        and tenant_id is not NULL and length(user_id)<11 
        group by tenant_id,user_id) a 
left join (SELECT tenant_id,
                    user_id as uid_last 
            FROM tezign_dw.dw_fact_web_tracking_log_add_h
            where dt is not null
            and biz_line_id = 'd14eae7480b640cab48af3db8567d298' and product_line_id = '0358a581866642d9b8e6c1c94e5a5f00' AND is_page_flag =1 
            and cast(create_date as date)> DATE_ADD(from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd'),-14)
            and cast(create_date as date)<= DATE_ADD(from_unixtime(unix_timestamp('20210728','yyyyMMdd'),'yyyy-MM-dd'),-7)
            and tenant_id not in ('t2', 't3', 't4', 't11', 't32', 't39', 't52', 't53', 't127', 't141', 't147', 't168',
                         't169', 't171', 't172', 't173', 't174', 't178', 't187', 't192', 't197', 't199', 't202') 
            and tenant_id is not NULL and length(user_id)<11 
            group by tenant_id,user_id) b 
on a.tenant_id=b.tenant_id 
and a.uid_now = b.uid_last 
group by a.tenant_id,a.uid_now,b.uid_last) c 
group by tenant_id`;

const errors = parser.validate(sql);

console.log(errors);

Problem
validate sql too slow, need about 10 seconds;

这里推荐你使用 Web Worker 来处理,可以尝试使用这个项目来集成:https://github.com/DTStack/monaco-sql-languages

from dt-sql-parser.

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.