日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

方案實現

本文主要為您介紹如何基于表格存儲實現海量氣象格點數據解決方案。

基于方案設計,表格存儲實現了一個Tablestore-Grid的library,基于這個library您可以非常方便地實現氣象格點數據的存儲、查詢和管理。提供以下接口:

public interface GridStore {
    /**
     * 創建相關的meta、data表,數據錄入前調用。
     * @throws Exception
     */
    void createStore() throws Exception;

    /**
     * 寫入gridDataSet的meta信息。
     * @param meta
     * @throws Exception
     */
    void putDataSetMeta(GridDataSetMeta meta) throws Exception;

    /**
     * 更新meta信息。
     * @param meta
     * @throws Exception
     */
    void updateDataSetMeta(GridDataSetMeta meta) throws Exception;

    /**
     * 通過gridDataSetId獲取meta。
     * @param dataSetId
     * @return
     * @throws Exception
     */
    GridDataSetMeta getDataSetMeta(String dataSetId) throws Exception;

    /**
     * 創建meta表的多元索引。
     * @param indexName
     * @param indexSchema
     * @throws Exception
     */
    void createMetaIndex(String indexName, IndexSchema indexSchema) throws Exception;

    /**
     * 通過多種查詢條件來查詢符合條件的數據集。
     * @param indexName 多元索引名。
     * @param query 查詢條件,可以通過QueryBuilder構建。
     * @param queryParams 查詢相關參數,包括offset、limit、sort等。
     * @return
     * @throws Exception
     */
    QueryGridDataSetResult queryDataSets(String indexName, Query query, QueryParams queryParams) throws Exception;

    /**
     * 獲取GridDataWriter用于寫入數據。
     * @param meta
     * @return
     */
    GridDataWriter getDataWriter(GridDataSetMeta meta);

    /**
     * 獲取GridDataFetcher用于讀取數據。
     * @param meta
     * @return
     */
    GridDataFetcher getDataFetcher(GridDataSetMeta meta);

    /**
     * 釋放資源。
     */
    void close();
}

public interface GridDataWriter {
    /**
     * 寫入一個二維平面。
     * @param variable 變量名。
     * @param t 時間維的值。
     * @param z 高度維的值。
     * @param grid2D 平面數據。
     * @throws Exception
     */
    void writeGrid2D(String variable, int t, int z, Grid2D grid2D) throws Exception;
}

public interface GridDataFetcher {
    /**
     * 設置要查詢的變量。
     * @param variables
     * @return
     */
    GridDataFetcher setVariablesToGet(Collection<String> variables);

    /**
     * 設置要讀取的各維度起始點和大小。
     * @param origin 各維度起始點。
     * @param shape 各維度大小。
     * @return
     */
    GridDataFetcher setOriginShape(int[] origin, int[] shape);

    /**
     * 獲取數據。
     * @return
     * @throws Exception
     */
    GridDataSet fetch() throws Exception;

數據錄入

數據錄入流程可以分為三部分:

  • 寫入putDataSetMeta接口寫入數據集的meta信息。

  • 通過GridDataWriter錄入整個數據集的數據。

  • 通過updateDataSetMeta接口更新數據集的meta信息,標記數據已經錄入完成。

示例如下:

以下示例中讀取一個NetCDF(氣象格點數據常用的格式)文件,然后將其中的數據通過GridDataWriter錄入到表格存儲中。通過GridDataWriter每次寫入時,只能寫入一個二維平面,所以需要在外層進行3層循環,分別枚舉變量維、時間維、高度維的值,然后讀取對應的二維平面的數據進行錄入。

public void importFromNcFile(GridDataSetMeta meta, String ncFileName) throws Exception {
    GridDataWriter writer = tableStoreGrid.getDataWriter(meta);
    NetcdfFile ncFile = NetcdfFile.open(ncFileName);
    List<Variable> variables = ncFile.getVariables();
    for (Variable variable : variables) {
        if (meta.getVariables().contains(variable.getShortName())) {
            for (int t = 0; t < meta.gettSize(); t++) {
                for (int z = 0; z < meta.getzSize(); z++) {
                    Array array = variable.read(new int[]{t, z, 0, 0}, new int[]{1, 1, meta.getxSize(), meta.getySize()});
                    Grid2D grid2D = new Grid2D(array.getDataAsByteBuffer(), variable.getDataType(),
                            new int[] {0, 0}, new int[] {meta.getxSize(), meta.getySize()});
                    writer.writeGrid2D(variable.getShortName(), t, z, grid2D);
                }
            }
        }
    }
}

數據查詢

GridDataFetcher支持對五維數據進行任意維度的查詢。第一維是變量維,通過setVariablesToGet接口設置要讀取哪些變量,其余四維通過設置起始點(origin)和讀取的大小(shape)就可以實現任意維度讀取。

public Array queryByTableStore(String dataSetId, String variable, int[] origin, int[] shape) throws Exception {
      GridDataFetcher fetcher = this.tableStoreGrid.getDataFetcher(this.tableStoreGrid.getDataSetMeta(dataSetId));
      fetcher.setVariablesToGet(Arrays.asList(variable));
      fetcher.setOriginShape(origin, shape);
      Grid4D grid4D = fetcher.fetch().getVariable(variable);
      return grid4D.toArray();
}

多條件檢索數據集

本方案中,對meta表建立多元索引后,可以支持通過各種組合條件來進行數據集檢索,查詢出符合條件的數據集,這個功能對于氣象管理系統來說非常重要。

示例如下:

假設我們要查詢已經完成入庫的,創建時間為最近一天的,來源為ECMWF(歐洲中期天氣預報中心)或者NMC(全國氣象中心),精度為1km的氣象預報,并按照創建時間從新到老排序,可以用以下代碼實現:

查詢條件: (status == DONE) and (create_time > System.currentTimeMillis - 86400000) and (source == "ECMWF" or source == "NMC") and (accuracy == "1km")

QueryGridDataSetResult result = tableStoreGrid.queryDataSets(
        ExampleConfig.GRID_META_INDEX_NAME,
        QueryBuilder.and()
                .equal("status", "DONE")
                .greaterThan("create_time", System.currentTimeMillis() - 86400000)
                .equal("accuracy", "1km")
                .query(QueryBuilder.or()
                        .equal("source", "ECMWF")
                        .equal("source", "NMC")
                        .build())
                .build(),
        new QueryParams(0, 10, new Sort(Arrays.<Sort.Sorter>asList(new FieldSort("create_time", SortOrder.DESC)))));

這一部分功能利用了表格存儲的多元索引,多元索引可以實現多字段組合查詢、模糊查詢、全文檢索、排序、范圍查詢、嵌套查詢、空間查詢等功能,給元數據管理場景提供了強大的底層能力。

代碼的獲取

您可以在GitHub上獲取Tablestore-Grid的實現代碼和示例代碼

技術支持

表格存儲為您提供專業的免費的技術咨詢服務,歡迎通過釘釘加入相應交流群。

  • 為互聯網應用、大數據、社交應用等開發者提供的最新技術交流群有36165029092(表格存儲技術交流群-3)。

    說明

    表格存儲用戶群11789671(表格存儲技術交流群)和23307953(表格存儲技術交流群-2)已滿,暫時無法加入。

    2e182faaf86c8352cb6fc99bd6371fb4.jpg

  • 為物聯網和時序模型開發者提供的技術交流群有44327024(物聯網存儲 IoTstore 開發者交流群)。

    be4365aa89c9377dd75d4b52b60d7144.jpg