minihippo commented on code in PR #5064:
URL: https://github.com/apache/hudi/pull/5064#discussion_r1083155827


##########
hudi-platform-service/hudi-metaserver/hudi-metaserver-server/src/main/java/org/apache/hudi/metaserver/store/RelationalDBBasedStorage.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.metaserver.store;
+
+import org.apache.hudi.metaserver.store.bean.InstantBean;
+import org.apache.hudi.metaserver.store.bean.TableBean;
+import org.apache.hudi.metaserver.store.jdbc.WrapperDao;
+import org.apache.hudi.metaserver.thrift.MetaserverStorageException;
+import org.apache.hudi.metaserver.thrift.THoodieInstant;
+import org.apache.hudi.metaserver.thrift.TState;
+import org.apache.hudi.metaserver.thrift.Table;
+
+import java.io.Serializable;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.apache.hudi.common.util.CollectionUtils.isNullOrEmpty;
+import static org.apache.hudi.common.util.ValidationUtils.checkState;
+
+/**
+ * Metadata store based on relation database.
+ */
+public class RelationalDBBasedStorage implements MetaserverStorage, 
Serializable {
+
+  private final WrapperDao tableDao = new WrapperDao.TableDao();
+  private final WrapperDao timelineDao = new WrapperDao.TimelineDao();
+
+  @Override
+  public void initStorage() throws MetaserverStorageException {
+    WrapperDao dao = new WrapperDao("DDLMapper");
+    dao.updateBySql("createDBs", null);
+    dao.updateBySql("createTables", null);
+    dao.updateBySql("createTableParams", null);
+    dao.updateBySql("createPartitions", null);
+    dao.updateBySql("createTableTimestamp", null);
+    dao.updateBySql("createInstant", null);
+    dao.updateBySql("createInstantMetadata", null);
+    dao.updateBySql("createFiles", null);
+  }
+
+  @Override
+  public boolean createDatabase(String db) throws MetaserverStorageException {
+    Map<String, Object> params = new HashMap<>();
+    params.put("databaseName", db);
+    return tableDao.insertBySql("insertDB", params) == 1;
+  }
+
+  @Override
+  public Long getDatabaseId(String db) throws MetaserverStorageException {
+    List<Long> ids = tableDao.queryForListBySql("selectDBId", db);
+    validate(ids, "db " + db);
+    return ids.isEmpty() ? null : ids.get(0);
+  }
+
+  @Override
+  public boolean createTable(Long dbId, Table table) throws 
MetaserverStorageException {
+    Map<String, Object> params = new HashMap<>();
+    params.put("dbId", dbId);
+    TableBean tableBean = new TableBean(table);
+    params.put("tableBean", tableBean);
+    return tableDao.insertBySql("insertTable", params) == 1;
+  }
+
+  @Override
+  public Table getTable(String db, String tb) throws 
MetaserverStorageException {
+    Map<String, Object> params = new HashMap<>();
+    params.put("databaseName", db);
+    params.put("tableName", tb);
+    List<TableBean> table = tableDao.queryForListBySql("selectTable", params);
+    validate(table, "table " + db + "." + tb);
+    return table.isEmpty() ? null : table.get(0).toTable();
+  }
+
+  @Override
+  public Long getTableId(String db, String tb) throws 
MetaserverStorageException {
+    Map<String, Object> params = new HashMap<>();
+    params.put("databaseName", db);
+    params.put("tableName", tb);
+    List<Long> ids = tableDao.queryForListBySql("selectTableId", params);
+    validate(ids, "table " + db + "." + tb);
+    return ids.isEmpty() ? null : ids.get(0);
+  }
+
+  @Override
+  public String createNewTimestamp(long tableId) throws 
MetaserverStorageException {
+    // todo: support SSS
+    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

Review Comment:
   fix



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to