Code Monkey home page Code Monkey logo

Comments (1)

HamaWhiteGG avatar HamaWhiteGG commented on July 18, 2024

Support, you can check the test case CepTest#testInsertSelectViewCep to see if it meets your needs. @zhangl0804

@Test
public void testInsertSelectViewCep() {
    context.execute("DROP VIEW IF EXISTS temperature_view ");

    context.execute("CREATE VIEW IF NOT EXISTS temperature_view AS " +
            "SELECT                                                     " +
            "   *                                                       " +
            "FROM                                                       " +
            "   temperature_source MATCH_RECOGNIZE (                    " +
            "       PARTITION BY rack_id                                " +
            "       ORDER BY ts                                         " +
            "       MEASURES                                            " +
            "           A.ts as start_ts,                               " +
            "           LAST(B.ts) as end_ts,                           " +
            "           A.temperature as start_temp,                    " +
            "           LAST(B.temperature) as end_temp,                " +
            "           AVG(B.temperature) as avg_temp                  " +
            "           ONE ROW PER MATCH                               " +
            "           AFTER MATCH SKIP TO NEXT ROW                    " +
            "           PATTERN (A B+ C) WITHIN INTERVAL '90' second    " +
            "           DEFINE                                          " +
            "               A as A.temperature < 50,                    " +
            "               B as B.temperature >=50,                    " +
            "               C as C.temperature < 50                     " +
            "   )"
    );

    String sql = "INSERT INTO print_sink (rack_id, start_ts, end_ts, start_temp, end_temp, avg_temp) " +
            "SELECT " +
            "   rack_id     ," +
            "   start_ts    ," +
            "   end_ts      ," +
            "   start_temp  ," +
            "   end_temp    ," +
            "   avg_temp     " +
            "FROM" +
            "   temperature_view";

    // variables A and B in transform are not replaced. LAST and AVG functions have also been replaced, and add CAST function.
    String[][] expectedArray = {
            {"temperature_source", "rack_id", "print_sink", "rack_id"},
            {"temperature_source", "ts", "print_sink", "start_ts", "CAST(A.ts):TIMESTAMP(3)"},
            {"temperature_source", "ts", "print_sink", "end_ts", "CAST(LAST(B.ts, 0)):TIMESTAMP(3)"},
            {"temperature_source", "temperature", "print_sink", "start_temp", "A.temperature"},
            {"temperature_source", "temperature", "print_sink", "end_temp", "LAST(B.temperature, 0)"},
            {"temperature_source", "temperature", "print_sink", "avg_temp", "CAST(/(SUM(B.temperature), COUNT(B.temperature))):INTEGER"}
    };

    analyzeLineage(sql, expectedArray);
}

from flink-sql-lineage.

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.