Skip to content

Commit

Permalink
refactor: support labels query of metaservice (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsy1001de authored Mar 27, 2024
1 parent f608d47 commit 86f7856
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
public class ConstModel {

public static final String default_id = "_id";
public static final String default_pk = "_uk";
public static final String default_type = "_type";
public static final String default_ip = "ip";
Expand All @@ -20,11 +19,7 @@ public class ConstModel {
public static final String default_modifier = "_modifier";
public static final String default_status = "_status";
public static final String default_modified = "_modified";
public static final String default_basic = "_basic";
public static final String default_annotation = "_annotation";
public static final String default_label = "_label";
public static final String READ_MYSQL_ENABLE = "readMysqlEnable";
public static final String WRITE_MYSQL_ENABLE = "writeMysqlEnable";
public static final String default_label = "labels";
public static final String META_CONFIG = "meta_config";
public static final String ANNOTATIONS = "annotations";
public static final String META_INDEX_CONFIG = "meta_index_config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.holoinsight.server.meta.core.service.bitmap;

import io.holoinsight.server.meta.common.util.ConstModel;
import io.holoinsight.server.meta.core.common.DimForkJoinPool;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -269,12 +270,21 @@ protected void deleteOneRow(MetaDataRow deleteLog) {
idRowsMap.remove(deleteLog.getId());
}

@SuppressWarnings("unchecked")
private void fillColsMapWithLabels(Map<String, MetaColData> colsMap, List<MetaDataRow> rows) {
DimForkJoinPool.get().submit(() -> rows.parallelStream().forEach(row -> {
Map<String, Object> labelMap = row.getValues();
if (labelMap != null) {
labelMap
.forEach((k, v) -> colsMap.putIfAbsent(k, new MetaColData(this.tableName, k, this)));
Map<String, Object> jsonMap = row.getValues();
if (jsonMap != null) {
jsonMap.forEach((k, v) -> colsMap.putIfAbsent(k, new MetaColData(this.tableName, k, this)));
if (jsonMap.containsKey(ConstModel.default_label)
&& jsonMap.get(ConstModel.default_label) instanceof Map<?, ?>) {
Map<String, Object> lableMap =
(Map<String, Object>) jsonMap.get(ConstModel.default_label);
if (null != lableMap) {
lableMap.forEach((k, v) -> colsMap.putIfAbsent(ConstModel.default_label + "." + k,
new MetaColData(this.tableName, ConstModel.default_label + "." + k, this)));
}
}
}
})).join();
log.info("fill cols with labels, rows={}, cols={}", CollectionUtils.size(rows),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.holoinsight.server.meta.core.service.bitmap;

import com.googlecode.javaewah.EWAHCompressedBitmap;
import io.holoinsight.server.meta.common.util.ConstModel;
import io.holoinsight.server.meta.core.common.DimForkJoinPool;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -58,21 +59,21 @@ public MetaColData(String tableName, String colName, Map<Object, EWAHCompressedB
}

public int getCount() {
if (loaded.get() == false) {
if (!loaded.get()) {
this.lazyLoad();
}
return this.valSizeCounter.get();
}

public EWAHCompressedBitmap getBitmap(Object val) {
if (loaded.get() == false) {
if (!loaded.get()) {
this.lazyLoad();
}
return this.val2BitMap.get(val);
}

public EWAHCompressedBitmap getBitmapOrDefault(Object val, EWAHCompressedBitmap defaultBitmap) {
if (loaded.get() == false) {
if (!loaded.get()) {
this.lazyLoad();
}
return this.val2BitMap.getOrDefault(val, defaultBitmap);
Expand Down Expand Up @@ -105,9 +106,9 @@ public List<EWAHCompressedBitmap> fuzzyGetBitmap(String targetVal, boolean isReg
* 懒加载
*/
public void lazyLoad() {
if (loaded.get() == false) {
if (!loaded.get()) {
synchronized (metaData) {
if (loaded.get() == false) {
if (!loaded.get()) {
StopWatch stopWatch = StopWatch.createStarted();
log.info(
"MetaColData lazy load start, table={}, col={}, size={}, logSize={}, valSize={}.",
Expand All @@ -129,9 +130,19 @@ public void lazyLoad() {
*
* @param changeLogs
*/
@SuppressWarnings("unchecked")
public void appendLogs(List<MetaDataRow> changeLogs) {
changeLogs.forEach(changeLog -> {
Object changeColVal = changeLog.getValues().get(colName);
Object changeColVal = null;
if (colName.startsWith(ConstModel.default_label + ".")) {
Object labels = changeLog.getValues().get(ConstModel.default_label);
if (labels instanceof Map<?, ?>) {
String labelCol = colName.substring(ConstModel.default_label.length() + 1);
changeColVal = ((Map<String, Object>) labels).get(labelCol);
}
} else {
changeColVal = changeLog.getValues().get(colName);
}
if (changeColVal == null) {
changeColVal = "null";
}
Expand Down

0 comments on commit 86f7856

Please sign in to comment.