@@ -1490,241 +1490,6 @@ private void test_M4_constantTimeSeries() {
14901490 }
14911491 }
14921492
1493- @ Test
1494- public void testUDTFJexl () {
1495- try (Connection connection = EnvFactory .getEnv ().getConnection ();
1496- Statement statement = connection .createStatement ()) {
1497- statement .execute ("CREATE TIMESERIES root.sg.d7.s1 with datatype=INT32,encoding=PLAIN" );
1498- statement .execute ("CREATE TIMESERIES root.sg.d7.s2 with datatype=FLOAT,encoding=PLAIN" );
1499- statement .execute ("CREATE TIMESERIES root.sg.d7.s3 with datatype=DOUBLE,encoding=PLAIN" );
1500- statement .execute ("CREATE TIMESERIES root.sg.d7.s4 with datatype=TEXT,encoding=PLAIN" );
1501- statement .execute ("CREATE TIMESERIES root.sg.d7.s5 with datatype=BOOLEAN,encoding=PLAIN" );
1502- statement .execute ("CREATE TIMESERIES root.sg.d7.s6 with datatype=INT64,encoding=PLAIN" );
1503- statement .execute ("CREATE TIMESERIES root.sg.d7.s7 with datatype=INT64,encoding=PLAIN" );
1504- statement .execute ("CREATE TIMESERIES root.sg.d7.s8 with datatype=FLOAT,encoding=PLAIN" );
1505- statement .execute ("CREATE TIMESERIES root.sg.d7.s9 with datatype=TEXT,encoding=PLAIN" );
1506- } catch (SQLException throwable ) {
1507- fail (throwable .getMessage ());
1508- }
1509- String [] SQL_FOR_SAMPLE_1 = new String [6 ];
1510- String [] SQL_FOR_SAMPLE_2 = new String [6 ];
1511- String [] SQL_FOR_SAMPLE_3 = new String [6 ];
1512- String [] SQL_FOR_SAMPLE_4 = new String [6 ];
1513- String [] SQL_FOR_SAMPLE_5 = new String [6 ];
1514- String [] SQL_FOR_SAMPLE_6 = new String [6 ];
1515- String [] SQL_FOR_SAMPLE_7 = new String [6 ];
1516- String [] SQL_FOR_SAMPLE_8 = new String [6 ];
1517- String [] SQL_FOR_SAMPLE_9 = new String [6 ];
1518- for (int i = 0 ; i < 5 ; i ++) {
1519- SQL_FOR_SAMPLE_1 [i ] =
1520- String .format (
1521- Locale .ENGLISH , "insert into root.sg.d7(time, s1) values (%d, %d)" , i , i + 1 );
1522- SQL_FOR_SAMPLE_2 [i ] =
1523- String .format (
1524- Locale .ENGLISH , "insert into root.sg.d7(time, s2) values (%d, %f)" , i , i + 1.0 );
1525- SQL_FOR_SAMPLE_3 [i ] =
1526- String .format (
1527- Locale .ENGLISH , "insert into root.sg.d7(time, s3) values (%d, %f)" , i , i + 1.0 );
1528- SQL_FOR_SAMPLE_4 [i ] =
1529- String .format (
1530- Locale .ENGLISH , "insert into root.sg.d7(time, s4) values (%d, '%s')" , i , "string" );
1531- SQL_FOR_SAMPLE_5 [i ] = String .format ("insert into root.sg.d7(time, s5) values (%d, true)" , i );
1532- SQL_FOR_SAMPLE_6 [i ] =
1533- String .format (
1534- Locale .ENGLISH , "insert into root.sg.d7(time, s6) values (%d, %d)" , i , i + 8 );
1535- SQL_FOR_SAMPLE_7 [i ] =
1536- String .format (
1537- Locale .ENGLISH , "insert into root.sg.d7(time, s7) values (%d, %d)" , i , i + 1 );
1538- SQL_FOR_SAMPLE_8 [i ] =
1539- String .format (
1540- Locale .ENGLISH , "insert into root.sg.d7(time, s8) values (%d, %f)" , i , i + 1.0 );
1541- SQL_FOR_SAMPLE_9 [i ] =
1542- String .format (
1543- Locale .ENGLISH , "insert into root.sg.d7(time, s9) values (%d, '%s')" , i , "string" );
1544- }
1545- SQL_FOR_SAMPLE_1 [5 ] =
1546- String .format (
1547- Locale .ENGLISH ,
1548- "insert into root.sg.d7(time, s1) values (%d, %d)" ,
1549- 10000000000L ,
1550- 5 + 1 );
1551- SQL_FOR_SAMPLE_2 [5 ] =
1552- String .format (
1553- Locale .ENGLISH ,
1554- "insert into root.sg.d7(time, s2) values (%d, %f)" ,
1555- 10000000000L ,
1556- 5 + 1.0 );
1557- SQL_FOR_SAMPLE_3 [5 ] =
1558- String .format (
1559- Locale .ENGLISH ,
1560- "insert into root.sg.d7(time, s3) values (%d, %f)" ,
1561- 10000000000L ,
1562- 5 + 1.0 );
1563- SQL_FOR_SAMPLE_4 [5 ] =
1564- String .format (
1565- Locale .ENGLISH ,
1566- "insert into root.sg.d7(time, s4) values (%d, '%s')" ,
1567- 10000000000L ,
1568- "string" );
1569- SQL_FOR_SAMPLE_5 [5 ] = String .format ("insert into root.sg.d7(time, s5) values (%d, true)" , 5 );
1570- SQL_FOR_SAMPLE_6 [5 ] =
1571- String .format (
1572- Locale .ENGLISH ,
1573- "insert into root.sg.d7(time, s6) values (%d, %d)" ,
1574- 10000000000L ,
1575- 5 + 8 );
1576- SQL_FOR_SAMPLE_7 [5 ] =
1577- String .format (
1578- Locale .ENGLISH ,
1579- "insert into root.sg.d7(time, s7) values (%d, %d)" ,
1580- 10000000000L ,
1581- 5 + 1 );
1582- SQL_FOR_SAMPLE_8 [5 ] =
1583- String .format (
1584- Locale .ENGLISH ,
1585- "insert into root.sg.d7(time, s8) values (%d, %f)" ,
1586- 10000000000L ,
1587- 5 + 1.0 );
1588- SQL_FOR_SAMPLE_9 [5 ] =
1589- String .format (
1590- Locale .ENGLISH ,
1591- "insert into root.sg.d7(time, s9) values (%d, '%s')" ,
1592- 10000000000L ,
1593- "string" );
1594- double [] ANSWER1 = new double [] {2 , 4 , 6 , 8 , 10 , 12 };
1595- double [] ANSWER2 = new double [] {2 , 4 , 6 , 8 , 10 , 12 };
1596- double [] ANSWER3 = new double [] {4 , 7 , 10 , 13 , 16 , 19 };
1597- String [] ANSWER4 =
1598- new String [] {"string2" , "string2" , "string2" , "string2" , "string2" , "string2" };
1599- double [] ANSWER7 = new double [] {1 , 4 , 9 , 16 , 25 , 36 };
1600- String [] ANSWER8 =
1601- new String [] {"string1" , "string4" , "string9" , "string16" , "string25" , "string36" };
1602- double [] ANSWER9 = new double [] {2 , 9 , 28 , 65 , 126 , 469 };
1603- try (Connection connection = EnvFactory .getEnv ().getConnection ();
1604- Statement statement = connection .createStatement ()) {
1605- for (int i = 0 ; i < 5 ; i ++) {
1606- statement .execute (SQL_FOR_SAMPLE_1 [i ]);
1607- statement .execute (SQL_FOR_SAMPLE_2 [i ]);
1608- statement .execute (SQL_FOR_SAMPLE_3 [i ]);
1609- statement .execute (SQL_FOR_SAMPLE_4 [i ]);
1610- statement .execute (SQL_FOR_SAMPLE_5 [i ]);
1611- statement .execute (SQL_FOR_SAMPLE_6 [i ]);
1612- statement .execute (SQL_FOR_SAMPLE_7 [i ]);
1613- statement .execute (SQL_FOR_SAMPLE_8 [i ]);
1614- statement .execute (SQL_FOR_SAMPLE_9 [i ]);
1615- }
1616- } catch (SQLException throwable ) {
1617- fail (throwable .getMessage ());
1618- }
1619-
1620- try (Connection connection = EnvFactory .getEnv ().getConnection ();
1621- Statement statement = connection .createStatement ()) {
1622- String functionName = "JEXL" ;
1623- String expr1 = "x -> {2 * x}" ;
1624- String expr2 = "x -> {x + x}" ;
1625- String expr3 = "x -> {x * 3 + 1}" ;
1626- String expr4 = "x -> {x + 2}" ;
1627- String expr5 = "x -> {x == true}" ;
1628- String expr6 = "x -> {x == x}" ;
1629- String expr7 = "(x, y) -> {x * y}" ;
1630- String expr8 = "(x, y, z) -> {x + y * z}" ;
1631- String expr9 = "(x, y, z, a) -> {x * y * z + (a ? 1 : -1)}" ;
1632- ResultSet resultSet =
1633- statement .executeQuery (
1634- String .format (
1635- "select %s(s1, 'expr'='%s'), "
1636- + "%s(s2, 'expr'='%s'), "
1637- + "%s(s3, 'expr'='%s'), "
1638- + "%s(s4, 'expr'='%s'), "
1639- + "%s(s5, 'expr'='%s'), "
1640- + "%s(s6, 'expr'='%s'), "
1641- + "%s(s7, s8, 'expr'='%s'), "
1642- + "%s(s4, s7, s1, 'expr'='%s'), "
1643- + "%s(s1, s7, s8, s5, 'expr'='%s') "
1644- + "from root.sg.d7" ,
1645- functionName ,
1646- expr1 ,
1647- functionName ,
1648- expr2 ,
1649- functionName ,
1650- expr3 ,
1651- functionName ,
1652- expr4 ,
1653- functionName ,
1654- expr5 ,
1655- functionName ,
1656- expr6 ,
1657- functionName ,
1658- expr7 ,
1659- functionName ,
1660- expr8 ,
1661- functionName ,
1662- expr9 ));
1663- int columnCount = resultSet .getMetaData ().getColumnCount ();
1664- assertEquals (1 + 9 , columnCount );
1665- for (int i = 0 ; i < 5 ; i ++) {
1666- resultSet .next ();
1667- assertEquals (ANSWER1 [i ], resultSet .getDouble (2 ), 0.01 );
1668- assertEquals (ANSWER2 [i ], resultSet .getDouble (3 ), 0.01 );
1669- assertEquals (ANSWER3 [i ], resultSet .getDouble (4 ), 0.01 );
1670- assertEquals (ANSWER4 [i ], resultSet .getString (5 ));
1671- assertTrue (resultSet .getBoolean (6 ));
1672- assertTrue (resultSet .getBoolean (7 ));
1673- assertEquals (ANSWER7 [i ], resultSet .getDouble (8 ), 0.01 );
1674- assertEquals (ANSWER8 [i ], resultSet .getString (9 ));
1675- assertEquals (ANSWER9 [i ], resultSet .getDouble (10 ), 0.01 );
1676- }
1677-
1678- resultSet =
1679- statement .executeQuery (
1680- String .format (
1681- "select %s(s1, 'expr'='%s'), "
1682- + "%s(s2, 'expr'='%s'), "
1683- + "%s(s3, 'expr'='%s'), "
1684- + "%s(s4, 'expr'='%s'), "
1685- + "%s(s5, 'expr'='%s'), "
1686- + "%s(s6, 'expr'='%s'), "
1687- + "%s(s7, s8, 'expr'='%s'), "
1688- + "%s(s4, s7, s1, 'expr'='%s'), "
1689- + "%s(s1, s7, s8, s5, 'expr'='%s') "
1690- + "from root.sg.d7 align by device" ,
1691- functionName ,
1692- expr1 ,
1693- functionName ,
1694- expr2 ,
1695- functionName ,
1696- expr3 ,
1697- functionName ,
1698- expr4 ,
1699- functionName ,
1700- expr5 ,
1701- functionName ,
1702- expr6 ,
1703- functionName ,
1704- expr7 ,
1705- functionName ,
1706- expr8 ,
1707- functionName ,
1708- expr9 ));
1709- columnCount = resultSet .getMetaData ().getColumnCount ();
1710- assertEquals (2 + 9 , columnCount );
1711- for (int i = 0 ; i < 5 ; i ++) {
1712- resultSet .next ();
1713- assertEquals (ANSWER1 [i ], resultSet .getDouble (2 + 1 ), 0.01 );
1714- assertEquals (ANSWER2 [i ], resultSet .getDouble (3 + 1 ), 0.01 );
1715- assertEquals (ANSWER3 [i ], resultSet .getDouble (4 + 1 ), 0.01 );
1716- assertEquals (ANSWER4 [i ], resultSet .getString (5 + 1 ));
1717- assertTrue (resultSet .getBoolean (6 + 1 ));
1718- assertTrue (resultSet .getBoolean (7 + 1 ));
1719- assertEquals (ANSWER7 [i ], resultSet .getDouble (8 + 1 ), 0.01 );
1720- assertEquals (ANSWER8 [i ], resultSet .getString (9 + 1 ));
1721- assertEquals (ANSWER9 [i ], resultSet .getDouble (10 + 1 ), 0.01 );
1722- }
1723- } catch (Exception e ) {
1724- e .printStackTrace ();
1725- }
1726- }
1727-
17281493 @ Test
17291494 public void testStringFunctions () {
17301495 String [] createSQLs =
0 commit comments