百度智能云

All Product Document

          Time-Spatial Database

          Management Interface

          In the sdk of v0.10.17, users are enabled to create/delete/query time series database instances through API.

          Create a TsdbAdminClient

          String ACCESS_KEY_ID = <your-access-key-id>;               // User's Access Key ID
          String SECRET_ACCESS_KEY = <your-secret-access-key>;       // User's Secret Access Key
          String ADMIN_ENDPOINT = "tsdb.gz.baidubce.com";            // Note: The endpoint is different from that  when creating a TsdbClient
           
          // create the configuration
          BceClientConfiguration config = new BceClientConfiguration()
                          .withCredentials(new DefaultBceCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY))
                          .withEndpoint(ADMIN_ENDPOINT);
           
          // initialize a TsdbAdminClient
          TsdbAdminClient tsdbAdminClient = new TsdbAdminClient(config);

          Configuration items in the BceClientConfiguration shall refer to the new TsdbAdminClient. Similarly, TsdbAdminClient also supports the use of HTTPS, and the configuration method refers to TsdbClient.

          Create a Time Series Database Instance

          The code example is as follows:

          String databaseName = "databasename";                            // name of the instance
          String description = "description";                              // instance description, optional
          int ingestDataPointsMonthly = 1;                                 // write quota, unit: millions of points/month
          int queryUnitsMonthly = 10;                                      // query quota, unit: ten thousands of points/month
          int purchaseLength = 1;                                          // purchase length, unit: month
          String couponName = <your-coupon-name>;                          // coupon name, optional
           
          CreateDatabaseRequest request = new CreateDatabaseRequest()
              .withDatabaseName(databaseName)
              .withDescription(description)
              .withIngestDataPointsMonthly(ingestDataPointsMonthly)
              .withQueryUnitsMonthly(queryUnitsMonthly)
              .withPurchaseLength(purchaseLength)
              .withCouponName(couponName);
           
          String clientToken = <your-client-token>;                        // ClientToken, used to guarantee the idempotence. Use the same clientToken when retrying to send creation requests.
          CreateDatabaseResponse response = tsdbAdminClient.createDatabase(request, clientToken);

          For fields of the return value, please refer to API Documentation.

          Delete a Time Series Database Instance

          The code example is as follows:

          String databaseId = <your-database-id>;                            // instance ID
          tsdbAdminClient.deleteDatabase(databaseId);

          Notes: Only Instance of deleting an expired time series database is permitted, otherwise an error will be reported.

          Get a Time Series Database Instance

          The code example is as follows:

          String databaseId = <your-database-id>;                            // instance ID
          GetDatabaseResponse database = tsdbAdminClient.getDatabase(databaseId);

          .

          Get a Time Series Database Instance List

          The code example is as follows:

          ListDatabaseResponse database = tsdbAdminClient.listDatabase();

          Create a Task to Delete Data Points

          // Assume that the user wants to delete the data points under the two metric: Wind and Temperature, and each metric uses tagFilter to filter. 
          
          // windTaskTagFilter is the filter of metric "Wind". 
          TaskTagFilter windTaskTagFilter = new TaskTagFilter();
          windTaskTagFilter.setTagKey("city");
          windTaskTagFilter.addIn("bj");
          
          // temperatureTaskTagFilter is the filter of metric "Temperature". 
          TaskTagFilter temperatureTaskTagFilter = new TaskTagFilter();
          temperatureTaskTagFilter.setTagKey("city");
          temperatureTaskTagFilter.addIn("gz");
          
          // The key of tags is metric, and the "value" is the list of TagFilter corresponding to metric. 
          Map<String, List<TaskTagFilter>> tags = new HashMap<String, List<TaskTagFilter>>();
          // Add "Wind" and its corresponding "Filter". 
          tags.put("wind", Arrays.asList(windTaskTagFilter));
          // Add "Temperature" and its corresponding "Filter". 
          tags.put("temperature", Arrays.asList(temperatureTaskTagFilter));
          
          // Create a deletion request and obtain response. 
          DeleteDatapointsRequest deleteRequest = new DeleteDatapointsRequest();
          deleteRequest.setDatabaseId("tsdb_sdfd434xxxx");
          // Set the metric to be deleted. If you do not set the "metrics" field or the "metricFieldsList" field, all metric and field data will be deleted. 
          // When deleting, it will query the "filter" corresponding to "metric" in tags for filtering. 
          deleteRequest.setMetrics(Arrays.asList("wind", "temperature"));
          deleteRequest.setTags(tags);
          DeleteDatapointsResponse deleteResponse = tsdbAdminClient.deleteDatapoints(deleteRequest);

          Create a Task of Exporting Data Points

          The code example is as follows:

          // Assume that the user wants to export the data points under the two metric: Wind and Temperature, and each metric uses tagFilter to filter. 
          
          // windTaskTagFilter is the filter of metric "Wind". 
          TaskTagFilter windTaskTagFilter = new TaskTagFilter();
          windTaskTagFilter.setTagKey("city");
          windTaskTagFilter.addIn("bj");
          
          // temperatureTaskTagFilter is the filter of metric "Temperature". 
          TaskTagFilter temperatureTaskTagFilter = new TaskTagFilter();
          temperatureTaskTagFilter.setTagKey("city");
          temperatureTaskTagFilter.addIn("gz");
          
          //  The key of tags is metric, and the "value" is the list of TagFilter corresponding to metric. 
          Map<String, List<TaskTagFilter>> tags = new HashMap<String, List<TaskTagFilter>>();
          // Add "Wind" and its corresponding "Filter". 
          tags.put("wind", Arrays.asList(windTaskTagFilter));
          // Add "Temperature" and its corresponding "Filter". 
          tags.put("temperature", Arrays.asList(temperatureTaskTagFilter));
           
          ExportDatapointsRequest exportRequest = new ExportDatapointsRequest();
          exportRequest.setDatabaseId("tsdb_sdfd434xxxx");
          exportRequest.setBosUrl("bos://iot-tsdb/test/");
          exportRequest.setFormat("csv");
          exportRequest.setSingleFile(true);
          // Set the metrics to be exported. If not, all metrics will be exported. For each metric to be exported, the corresponding filter will be queried in tags. 
          // Carry out filtering 
          exportRequest.setMetrics(Arrays.asList("wind", "temperature"));
          exportRequest.setTags(tags);
          ExportDatapointsResponse exportResponse = tsdbAdminClient.exportDatapoints(exportRequest);

          Get Task Information

          The code example is as follows:

          GetTaskRequest getTaskRequest = new GetTaskRequest();
          getTaskRequest.setDatabaseId("tsdb_sdfd434xxxx");
          getTaskRequest.setTaskId("taskId");
          GetTaskResponse response = tsdbAdminClient.getTask(getTaskRequest);
          Previous
          Gzip Compression Instruction of Writing Data Points
          Next
          Version Description