You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@iotdb.apache.org by "changxue (Jira)" <ji...@apache.org> on 2023/02/22 01:28:00 UTC

[jira] [Created] (IOTDB-5569) [session]SessionDataSet should more friendly to user

changxue created IOTDB-5569:
-------------------------------

             Summary: [session]SessionDataSet should more friendly to user
                 Key: IOTDB-5569
                 URL: https://issues.apache.org/jira/browse/IOTDB-5569
             Project: Apache IoTDB
          Issue Type: Improvement
            Reporter: changxue
            Assignee: Yukun Zhou


SessionDataSet should more friendly to user

When I get the result of an sql statement with session.executeQueryStatement(sql), I'm confusing with how can I get the proper result of different result.

There are 2 kinds of result:
 # select * from root.xx;
{code:java}
String sql="select count(*) from root.ln.wf01.wt01;";
SessionDataSet records = session.executeQueryStatement(sql);
SessionDataSet.DataIterator recordsIter = records.iterator();
int count = 0;
while (recordsIter.next()) {
    // I must know data type previously and I'm confusing of the index, it's only for int values or for all columns.
    count = recordsIter.getInt(1);
    System.out.println(count);
}{code}

 # select last(*) from root.xx;

{code:java}
//        IoTDB> select last(*) from root.ln.wf01.wt01
//                +-----------------------------+-----------------------------+-----+--------+
//                |                         Time|                   Timeseries|Value|DataType|
//                +-----------------------------+-----------------------------+-----+--------+
//                |1970-01-01T08:00:00.001+08:00|root.ln.wf01.wt01.temperature|  2.6|   FLOAT|
//|1970-01-01T08:00:00.001+08:00|     root.ln.wf01.wt01.status| true| BOOLEAN|
//                +-----------------------------+-----------------------------+-----+--------+
//                        Total line number = 2
//        It costs 0.016s
//        IoTDB> select * from root.ln.wf01.wt01;
//        +-----------------------------+-----------------------------+------------------------+
//                |                         Time|root.ln.wf01.wt01.temperature|root.ln.wf01.wt01.status|
//                +-----------------------------+-----------------------------+------------------------+
//                |1970-01-01T08:00:00.001+08:00|                          2.6|                    true|
//                +-----------------------------+-----------------------------+------------------------+
        String sql = "select last(*) from root.ln.wf01.wt01";
        SessionDataSet dataSet = session.executeQueryStatement(sql);
        while (dataSet.hasNext()) {
            RowRecord records = dataSet.next();
            out.println(records.getFields().get(0).getStringValue());
            // string value is available, but if I'd like to get specified data type like FLOAT, I must add switch statement.It's a bad experience.             out.println(records.getFields().get(1).getStringValue());
            // useless, return the default initialized value
            out.println(records.getFields().get(1).getObjectValue(TSDataType.BOOLEAN));
//            out.println(records.getFields().get(1).toString());
        } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)