org.apache.kylin.common.persistence.ResourceStore.getResource()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(102)

本文整理了Java中org.apache.kylin.common.persistence.ResourceStore.getResource方法的一些代码示例,展示了ResourceStore.getResource的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResourceStore.getResource方法的具体详情如下:
包路径:org.apache.kylin.common.persistence.ResourceStore
类名称:ResourceStore
方法名:getResource

ResourceStore.getResource介绍

[英]Caution: Caller must close the returned RawResource.
[中]警告:调用方必须关闭返回的资源。

代码示例

代码示例来源:origin: apache/kylin

private ExecutablePO readJobResource(String path) throws IOException {
  return store.getResource(path, JOB_SERIALIZER);
}

代码示例来源:origin: apache/kylin

private ExecutableOutputPO readJobOutputResource(String path) throws IOException {
  return store.getResource(path, JOB_OUTPUT_SERIALIZER);
}

代码示例来源:origin: apache/kylin

DictionaryInfo load(String resourcePath, boolean loadDictObj) throws IOException {
  ResourceStore store = getStore();
  logger.info("DictionaryManager(" + System.identityHashCode(this) + ") loading DictionaryInfo(loadDictObj:" + loadDictObj + ") at " + resourcePath);
  DictionaryInfo info = store.getResource(resourcePath, loadDictObj ? DictionaryInfoSerializer.FULL_SERIALIZER : DictionaryInfoSerializer.INFO_SERIALIZER);
  return info;
}

代码示例来源:origin: apache/kylin

/**
 * Read a resource, return null in case of not found or is a folder.
 */
final public <T extends RootPersistentEntity> T getResource(String resPath, Serializer<T> serializer)
    throws IOException {
  return getResource(resPath, new ContentReader<T>(serializer));
}

代码示例来源:origin: apache/kylin

private SnapshotTable load(String resourcePath, boolean loadData) throws IOException {
  logger.info("Loading snapshotTable from " + resourcePath + ", with loadData: " + loadData);
  ResourceStore store = getStore();
  SnapshotTable table = store.getResource(resourcePath, loadData ? SnapshotTableSerializer.FULL_SERIALIZER : SnapshotTableSerializer.INFO_SERIALIZER);
  if (loadData)
    logger.debug("Loaded snapshot at " + resourcePath);
  return table;
}

代码示例来源:origin: apache/kylin

public String cat(KylinConfig config, String path) throws IOException {
  ResourceStore store = ResourceStore.getStore(config);
  StringBuffer sb = new StringBuffer();
  String line;
  try (InputStream is = store.getResource(path).content();
      BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
    while ((line = br.readLine()) != null) {
      System.out.println(line);
      sb.append(line).append('\n');
    }
  }
  return sb.toString();
}

代码示例来源:origin: apache/kylin

public void refresh() throws IOException {
  ObjectMapper mapper = new ObjectMapper();
  mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
  List<String> all = Lists.newArrayList();
  collectFiles(this.store, "/", all);
  for (String path : all) {
    if (path.endsWith(MetadataConstants.FILE_SURFIX) && !(path.startsWith(ResourceStore.DICT_RESOURCE_ROOT) || path.startsWith(ResourceStore.SNAPSHOT_RESOURCE_ROOT))) {
      logger.info("Updating metadata version of path {}", path);
      ObjectNode objectNode = (ObjectNode) mapper.readTree(this.store.getResource(path).content());
      objectNode.put("version", version);
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      mapper.writeValue(baos, objectNode);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      this.store.putResource(path, bais, System.currentTimeMillis());
    }
  }
}

代码示例来源:origin: apache/kylin

public Draft load(String uuid) throws IOException {
  ResourceStore store = getStore();
  Draft draft = store.getResource(Draft.concatResourcePath(uuid), DRAFT_SERIALIZER);
  return draft;
}

代码示例来源:origin: apache/kylin

private ExtTableSnapshotInfo load(String resourcePath) throws IOException {
  ResourceStore store = TableMetadataManager.getInstance(this.config).getStore();
  ExtTableSnapshotInfo snapshot = store.getResource(resourcePath, SNAPSHOT_SERIALIZER);
  return snapshot;
}

代码示例来源:origin: apache/kylin

public List<Draft> list(String project) throws IOException {
  List<Draft> result = new ArrayList<>();
  ResourceStore store = getStore();
  NavigableSet<String> listPath = store.listResources(ResourceStore.DRAFT_RESOURCE_ROOT);
  if (listPath == null)
    return result;
  
  for (String path : listPath) {
    Draft draft = store.getResource(path, DRAFT_SERIALIZER);
    
    if (draft == null)
      continue;
    
    if (project == null || project.equals(draft.getProject()))
      result.add(draft);
  }
  return result;
}

代码示例来源:origin: apache/kylin

public List<String> getPkValues(ColumnDesc pk) throws IOException {
  if (existsInStore(pk.getTable()) == false)
    return null;
  List<String> r = new ArrayList<>();
  BufferedReader in = new BufferedReader(
      new InputStreamReader(outputStore.getResource(path(pk.getTable())).content(), "UTF-8"));
  try {
    String line;
    while ((line = in.readLine()) != null) {
      r.add(line.split(",")[pk.getZeroBasedIndex()]);
    }
  } finally {
    IOUtils.closeQuietly(in);
  }
  return r;
}

代码示例来源:origin: apache/kylin

public List<Query> getQueries(final String creator, final String project) throws IOException {
  if (null == creator) {
    return null;
  }
  List<Query> queries = new ArrayList<>();
  QueryRecord record = queryStore.getResource(getQueryKeyById(creator), QueryRecordSerializer.getInstance());
  if (record != null) {
    for (Query query : record.getQueries()) {
      if (project == null || query.getProject().equals(project))
        queries.add(query);
    }
  }
  return queries;
}

代码示例来源:origin: apache/kylin

public BadQueryHistory getBadQueriesForProject(String project) throws IOException {
  BadQueryHistory badQueryHistory = getStore().getResource(getResourcePathForProject(project), BAD_QUERY_INSTANCE_SERIALIZER);
  if (badQueryHistory == null) {
    badQueryHistory = new BadQueryHistory(project);
  }
  logger.debug("Loaded " + badQueryHistory.getEntries().size() + " Bad Query(s)");
  return badQueryHistory;
}

代码示例来源:origin: apache/kylin

public static void dumpResources(KylinConfig kylinConfig, File metaDir, Set<String> dumpList) throws IOException {
  long startTime = System.currentTimeMillis();
  ResourceStore from = ResourceStore.getStore(kylinConfig);
  KylinConfig localConfig = KylinConfig.createInstanceFromUri(metaDir.getAbsolutePath());
  ResourceStore to = ResourceStore.getStore(localConfig);
  for (String path : dumpList) {
    RawResource res = from.getResource(path);
    if (res == null)
      throw new IllegalStateException("No resource found at -- " + path);
    to.putResource(path, res.content(), res.lastModified());
    res.content().close();
  }
  logger.debug("Dump resources to {} took {} ms", metaDir, System.currentTimeMillis() - startTime);
}

代码示例来源:origin: apache/kylin

private static long testReadPerformance(ResourceStore store) throws IOException {
  long startTime = System.currentTimeMillis();
  int step = 0; //avoid compiler optimization
  for (int i = 0; i < TEST_RESOURCE_COUNT; i++) {
    String resourcePath = PERFORMANCE_TEST_ROOT_PATH + "/res_" + i;
    StringEntity t = store.getResource(resourcePath, StringEntity.serializer);
    step |= t.toString().length();
  }
  logger.info("step : " + step);
  return System.currentTimeMillis() - startTime;
}

代码示例来源:origin: apache/kylin

public T reloadAt(String path) {
  try {
    T entity = store.getResource(path, serializer);
    if (entity == null) {
      logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null");
      cache.removeLocal(resourceName(path));
      return null;
    }
    // mark cached object
    entity.setCachedAndShared(true);
    entity = initEntityAfterReload(entity, resourceName(path));
    if (path.equals(resourcePath(entity.resourceName())) == false)
      throw new IllegalStateException("The entity " + entity + " read from " + path
          + " will save to a different path " + resourcePath(entity.resourceName()));
    
    cache.putLocal(entity.resourceName(), entity);
    return entity;
  } catch (Exception e) {
    throw new IllegalStateException("Error loading " + entityType.getSimpleName() + " at " + path, e);
  }
}

代码示例来源:origin: apache/kylin

public String getMetaStoreUUID() throws IOException {
  if (!exists(ResourceStore.METASTORE_UUID_TAG)) {
    checkAndPutResource(ResourceStore.METASTORE_UUID_TAG, new StringEntity(createMetaStoreUUID()), 0,
        StringEntity.serializer);
  }
  StringEntity entity = getResource(ResourceStore.METASTORE_UUID_TAG, StringEntity.serializer);
  return entity.toString();
}

代码示例来源:origin: apache/kylin

public static void appendFactTableData(String factTableContent, String factTableName) throws IOException {
  // Write to resource store
  ResourceStore store = ResourceStore.getStore(config());
  InputStream in = new ByteArrayInputStream(factTableContent.getBytes("UTF-8"));
  String factTablePath = "/data/" + factTableName + ".csv";
  File tmpFile = File.createTempFile(factTableName, "csv");
  FileOutputStream out = new FileOutputStream(tmpFile);
  InputStream tempIn = null;
  try {
    if (store.exists(factTablePath)) {
      InputStream oldContent = store.getResource(factTablePath).content();
      IOUtils.copy(oldContent, out);
    }
    IOUtils.copy(in, out);
    IOUtils.closeQuietly(in);
    IOUtils.closeQuietly(out);
    store.deleteResource(factTablePath);
    tempIn = new FileInputStream(tmpFile);
    store.putResource(factTablePath, tempIn, System.currentTimeMillis());
  } finally {
    IOUtils.closeQuietly(out);
    IOUtils.closeQuietly(in);
    IOUtils.closeQuietly(tempIn);
  }
}

代码示例来源:origin: apache/kylin

/**
 * @param cuboidScheduler if it's null, part of it's functions will not be supported
 */
public CubeStatsReader(CubeSegment cubeSegment, CuboidScheduler cuboidScheduler, KylinConfig kylinConfig)
    throws IOException {
  ResourceStore store = ResourceStore.getStore(kylinConfig);
  String statsKey = cubeSegment.getStatisticsResourcePath();
  RawResource resource = store.getResource(statsKey);
  if (resource == null)
    throw new IllegalStateException("Missing resource at " + statsKey);
  File tmpSeqFile = writeTmpSeqFile(resource.content());
  Path path = new Path(HadoopUtil.fixWindowsPath("file://" + tmpSeqFile.getAbsolutePath()));
  CubeStatsResult cubeStatsResult = new CubeStatsResult(path, kylinConfig.getCubeStatsHLLPrecision());
  tmpSeqFile.delete();
  this.seg = cubeSegment;
  this.cuboidScheduler = cuboidScheduler;
  this.samplingPercentage = cubeStatsResult.getPercentage();
  this.mapperNumberOfFirstBuild = cubeStatsResult.getMapperNumber();
  this.mapperOverlapRatioOfFirstBuild = cubeStatsResult.getMapperOverlapRatio();
  this.cuboidRowEstimatesHLL = cubeStatsResult.getCounterMap();
  this.sourceRowCount = cubeStatsResult.getSourceRecordCount();
}

代码示例来源:origin: apache/kylin

public void saveTableExt(TableExtDesc tableExt, String prj) throws IOException {
  try (AutoLock lock = srcExtMapLock.lockForWrite()) {
    if (tableExt.getUuid() == null || tableExt.getIdentity() == null) {
      throw new IllegalArgumentException();
    }
    // updating a legacy global table
    if (tableExt.getProject() == null) {
      if (getTableExt(tableExt.getIdentity(), prj).getProject() != null)
        throw new IllegalStateException(
            "Updating a legacy global TableExtDesc while a project level version exists: "
                + tableExt.getIdentity() + ", " + prj);
      prj = tableExt.getProject();
    }
    tableExt.init(prj);
    // what is this doing??
    String path = TableExtDesc.concatResourcePath(tableExt.getIdentity(), prj);
    ResourceStore store = getStore();
    TableExtDesc t = store.getResource(path, TABLE_EXT_SERIALIZER);
    if (t != null && t.getIdentity() == null)
      store.deleteResource(path);
    srcExtCrud.save(tableExt);
  }
}

相关文章