Skip to content

Commit

Permalink
[IOTDB-503] Add checkTimeseriesExists for session
Browse files Browse the repository at this point in the history
  • Loading branch information
vesense authored and jixuan1989 committed Feb 20, 2020
1 parent a1a56ef commit 0155009
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ public static void main(String[] args)
session.open();

session.setStorageGroup("root.sg1");
session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
if (session.checkTimeseriesExists("root.sg1.d1.s1")) {
session.createTimeseries("root.sg1.d1.s1", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
}
if (session.checkTimeseriesExists("root.sg1.d1.s2")) {
session.createTimeseries("root.sg1.d1.s2", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
}
if (session.checkTimeseriesExists("root.sg1.d1.s3")) {
session.createTimeseries("root.sg1.d1.s3", TSDataType.INT64, TSEncoding.RLE, CompressionType.SNAPPY);
}

insert();
insertInBatch();
Expand Down
9 changes: 9 additions & 0 deletions session/src/main/java/org/apache/iotdb/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ public TSStatus createTimeseries(String path, TSDataType dataType,
}
}

public boolean checkTimeseriesExists(String path) throws IoTDBSessionException {
checkPathValidity(path);
try {
return executeQueryStatement(String.format("SHOW TIMESERIES %s", path)).hasNext();
} catch (Exception e) {
throw new IoTDBSessionException(e);
}
}

private TSStatus checkAndReturn(TSStatus resp) {
if (resp.statusType.getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
logger.error(resp.statusType.getMessage());
Expand Down

0 comments on commit 0155009

Please sign in to comment.