• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DocumentStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.ojai.DocumentStream的典型用法代码示例。如果您正苦于以下问题:Java DocumentStream类的具体用法?Java DocumentStream怎么用?Java DocumentStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DocumentStream类属于org.ojai包,在下文中一共展示了DocumentStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: indexJSONTableDocuments

import org.ojai.DocumentStream; //导入依赖的package包/类
private void indexJSONTableDocuments(TransportClient client, String indexName, String typeName, String tablePath, String... fields) {

        loginTestUser(TEST_USER_NAME, TEST_USER_GROUP);

        // Create an OJAI connection to MapR cluster
        Connection connection = DriverManager.getConnection(CONNECTION_URL);

        // Get an instance of OJAI DocumentStore
        final DocumentStore store = connection.getStore(tablePath);

        DocumentStream documentStream = store.find(fields);
        for (Document document : documentStream) {

            IndexResponse response = client.prepareIndex(indexName, typeName, document.getId().getString())
                    .setSource(document.asJsonString(), XContentType.JSON)
                    .get();

            log.info("Elasticsearch Index Response: '{}'", response);
        }

        // Close this instance of OJAI DocumentStore
        store.close();

        // Close the OJAI connection and release any resources held by the connection
        connection.close();
    }
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:27,代码来源:MaprMusicElasticSearchService.java


示例2: getTotalNumByLanguage

import org.ojai.DocumentStream; //导入依赖的package包/类
/**
 * Returns number of albums according to the specified language.
 *
 * @param language language code.
 * @return number of albums with specified language code.
 */
public long getTotalNumByLanguage(String language) {
    return processStore((connection, store) -> {

        Stopwatch stopwatch = Stopwatch.createStarted();

        QueryCondition languageEqualsCondition = connection.newCondition()
                .is("language", QueryCondition.Op.EQUAL, language)
                .build();

        Query query = connection.newQuery()
                .select("_id")
                .where(languageEqualsCondition)
                .build();

        DocumentStream documentStream = store.findQuery(query);
        long totalNum = 0;
        for (Document ignored : documentStream) {
            totalNum++;
        }

        log.debug("Counting '{}' albums by language '{}' took {}", totalNum, language, stopwatch);

        return totalNum;
    });
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:AlbumDao.java


示例3: getByUserId

import org.ojai.DocumentStream; //导入依赖的package包/类
/**
 * Returns list of Artist rates by user identifier.
 *
 * @param userId user's identifier.
 * @return list of Artist rates.
 */
public List<ArtistRate> getByUserId(String userId) {
    return processStore((connection, store) -> {

        Stopwatch stopwatch = Stopwatch.createStarted();
        Query query = connection.newQuery().where(
                connection.newCondition()
                        .is("user_id", QueryCondition.Op.EQUAL, userId)
                        .build()
        ).build();

        // Fetch all OJAI Documents from this store according to the built query
        DocumentStream documentStream = store.findQuery(query);
        List<ArtistRate> rates = new ArrayList<>();
        for (Document document : documentStream) {
            ArtistRate rate = mapOjaiDocument(document);
            if (rate != null) {
                rates.add(rate);
            }
        }

        log.debug("Get '{}' rates by user id '{}' took {}", rates.size(), userId, stopwatch);

        return rates;
    });
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:ArtistRateDao.java


示例4: getByArtistId

import org.ojai.DocumentStream; //导入依赖的package包/类
/**
 * Returns list of Artist rates by artist identifier.
 *
 * @param artistId artist's identifier.
 * @return list of Artist rates.
 */
public List<ArtistRate> getByArtistId(String artistId) {
    return processStore((connection, store) -> {

        Stopwatch stopwatch = Stopwatch.createStarted();
        Query query = connection.newQuery().where(
                connection.newCondition()
                        .is("document_id", QueryCondition.Op.EQUAL, artistId)
                        .build()
        ).build();

        // Fetch all OJAI Documents from this store according to the built query
        DocumentStream documentStream = store.findQuery(query);
        List<ArtistRate> rates = new ArrayList<>();
        for (Document document : documentStream) {
            ArtistRate rate = mapOjaiDocument(document);
            if (rate != null) {
                rates.add(rate);
            }
        }

        log.debug("Get '{}' rates by artist id '{}' took {}", rates.size(), artistId, stopwatch);

        return rates;
    });
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:ArtistRateDao.java


示例5: getList

import org.ojai.DocumentStream; //导入依赖的package包/类
/**
 * Returns list of all documents.
 *
 * @return list of documents.
 */
public List<T> getList() {
    return processStore((connection, store) -> {

        Stopwatch stopwatch = Stopwatch.createStarted();

        // Fetch all OJAI Documents from this store
        DocumentStream documentStream = store.find();
        List<T> documents = new ArrayList<>();
        for (Document document : documentStream) {
            T doc = mapOjaiDocument(document);
            if (doc != null) {
                documents.add(doc);
            }
        }

        log.debug("Get list of '{}' documents from '{}' table. Elapsed time: {}", documents.size(), tablePath,
                stopwatch);

        return documents;
    });
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:27,代码来源:MaprDbDao.java


示例6: recomputeStatistics

import org.ojai.DocumentStream; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void recomputeStatistics() {

    MaprDbDao.OjaiStoreAction<Long> countAction = ((connection, store) -> {

        long total = 0;
        DocumentStream documentStream = store.find("_id");
        for (Document document : documentStream) {
            total++;
        }

        return total;
    });

    long albumsTotal = albumDao.processStore(countAction);
    Statistic albumsStatistic = getStatisticForTable(ALBUMS_TABLE_NAME);
    albumsStatistic.setDocumentNumber(albumsTotal);
    statisticDao.update(ALBUMS_TABLE_NAME, albumsStatistic);

    long artistsTotal = artistDao.processStore(countAction);
    Statistic artistsStatistic = getStatisticForTable(ARTISTS_TABLE_NAME);
    artistsStatistic.setDocumentNumber(artistsTotal);
    statisticDao.update(ARTISTS_TABLE_NAME, artistsStatistic);
}
 
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:28,代码来源:CdcStatisticService.java


示例7: getData

import org.ojai.DocumentStream; //导入依赖的package包/类
@GET
@Produces(APPLICATION_JSON)
public Response getData() throws JsonProcessingException {

    List<Document> items = new ArrayList<>();
    ObjectMapper object = new ObjectMapper();
    table = dao.getStatsTable();

    QueryCondition c = MapRDB.newCondition().is("simulationId", QueryCondition.Op.EQUAL, dao.getLastSimulationID());
    DocumentStream rs = table.find(c);

    if (rs != null) {
        for(Document doc : rs) {
            items.add(doc);
            System.out.println(doc.asJsonString());
        }
        rs.close();
    }
    return Response.ok(object.writeValueAsString(items)).build();
}
 
开发者ID:mapr-demos,项目名称:telco-anomaly-detection-spark,代码行数:21,代码来源:TelcoRestApi.java


示例8: newDocumentStream

import org.ojai.DocumentStream; //导入依赖的package包/类
static DocumentStream newDocumentStream(FileSystem fs,
    Path path, Map<FieldPath, Type> map, Events.Delegate delegate)
        throws IllegalArgumentException, IOException {
  final InputStream in = fs.open(path);
  return new JsonDocumentStream(in, map, delegate) {
    @Override
    public void close() {
      try {
        super.close();
      } finally {
        try {
          in.close();
        } catch (IOException e) {
          throw new OjaiException(e);
        }
      }
    }
  };
}
 
开发者ID:ojai,项目名称:ojai,代码行数:20,代码来源:JsonDocumentStream.java


示例9: getDocument

import org.ojai.DocumentStream; //导入依赖的package包/类
@Override
public Document getDocument() {
  Preconditions.checkState(jsonGenerator.isClosed(), "The document has not been built.");

  if (b != null) {
    byte[] barray = b.getByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(barray);
    DocumentStream documentStream = Json.newDocumentStream(inputStream);
    Iterator<Document> iter = documentStream.iterator();
    if (iter.hasNext()) {
      Document r = iter.next();
      return r;
    }
  }
  return null;
}
 
开发者ID:ojai,项目名称:ojai,代码行数:17,代码来源:JsonDocumentBuilder.java


示例10: testResources

import org.ojai.DocumentStream; //导入依赖的package包/类
private void testResources(String resource) throws IOException {
  try (InputStream testJson = getJsonStream(resource);
       DocumentStream stream = Json.newDocumentStream(testJson);
       InputStream testJson1 = getJsonStream(resource);
       DocumentStream stream1 = Json.newDocumentStream(testJson1);
       InputStream testJson2 = getJsonStream(resource);
       DocumentStream stream2 = Json.newDocumentStream(testJson2);) {
    for (Document document : stream) {
      assertEquals(document, document); // self comparison
    }
    // same documents extracted from different streams
    Iterator<Document> itr1 = stream1.iterator();
    Iterator<Document> itr2 = stream2.iterator();
    while (itr1.hasNext()) {
      assertEquals(itr1.next(), itr2.next());
    }
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:19,代码来源:TestJsonDocumentEquals.java


示例11: testDocumentIterator

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testDocumentIterator() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/multidocument.json");
       DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    Iterator<Document> it = stream.iterator();
    Document document;
    while (it.hasNext()) {
      document = it.next();
      testDocumentElements(document);
      documentCount++;
    }
    assertEquals(4, documentCount);
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:17,代码来源:TestJsonDocumentStream.java


示例12: testDocumentIteratorNextMethod

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testDocumentIteratorNextMethod() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/multidocument.json");
       DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    Iterator<Document> it = stream.iterator();

    Document rec ;
    try {
      while ((rec = it.next()) != null) {
        documentCount++;
        if (documentCount == 1) {
          assertEquals("John", rec.getString("name.first"));
        }
      }
    } catch (Exception e) {
      assertEquals(4, documentCount);
    }
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:22,代码来源:TestJsonDocumentStream.java


示例13: testFetchAndParseJsonDocumentStream

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testFetchAndParseJsonDocumentStream() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/manydocs.json");
      DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    for (DocumentReader reader : stream.documentReaders()) {
      documentCount++;
      if (documentCount == 1) {
        validateDocumentReaderOne(reader);
      } else if (documentCount == 2) {
        validateDocumentReaderTwo(reader);
      } else {
        validateDocumentReaderThree(reader);
      }
    }
    assertEquals(3, documentCount);
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:20,代码来源:TestJsonDocumentStreamFormat.java


示例14: testParseStreamWithManyArrays

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testParseStreamWithManyArrays() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/manyarray.json");
      DocumentStream stream = Json.newDocumentStream(in)) {

    int documentCount = 0;
    for (DocumentReader reader : stream.documentReaders()) {
      documentCount++;
      if (documentCount == 1) {
        validateDocumentReaderOne(reader);
      }
      if (documentCount == 2) {
        validateDocumentReaderTwo(reader);
      }
      if (documentCount == 3){
        validateDocumentReaderThree(reader);
      }
      if (documentCount == 5) {
        validateDocumentReaderFive(reader);
      }
    }
    assertEquals(5, documentCount);
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:25,代码来源:TestJsonDocumentStreamFormat.java


示例15: testEmptyMissingField

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testEmptyMissingField() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("a.a1", "b.b1");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:17,代码来源:TestDocumentReaderWithProjection.java


示例16: testProjectScalarFieldAsContainer

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testProjectScalarFieldAsContainer() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("c.c1", "f.g.h[2]");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "c");
    assertMapEvent(r, EventType.END_MAP, "c");

    assertMapEvent(r, EventType.START_MAP, "f");
    assertMapEvent(r, EventType.START_MAP, "g");
    assertMapEvent(r, EventType.START_ARRAY, "h");
    assertMapEvent(r, EventType.END_ARRAY, "h");
    assertMapEvent(r, EventType.END_MAP, "g");
    assertMapEvent(r, EventType.END_MAP, "f");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:27,代码来源:TestDocumentReaderWithProjection.java


示例17: testProjectParentAndChild

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testProjectParentAndChild() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("k", "k.l.l1");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "k");
    assertMapEvent(r, EventType.START_MAP, "l");
    assertMapEvent(r, EventType.START_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l2");
    assertMapEvent(r, EventType.END_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l3");
    assertMapEvent(r, EventType.END_MAP, "l");
    assertMapEvent(r, EventType.END_MAP, "k");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:26,代码来源:TestDocumentReaderWithProjection.java


示例18: testProjectChildParentAndChild

import org.ojai.DocumentStream; //导入依赖的package包/类
@Test
public void testProjectChildParentAndChild() throws Exception {
  try (InputStream testJson = getJsonStream("org/ojai/test/data/test1.json");
      DocumentStream stream = Json.newDocumentStream(testJson);) {
    DocumentReader reader = stream.iterator().next().asReader();
    FieldProjector projector = new FieldProjector("k.l.l1", "k", "k.l.l1");

    DocumentReaderWithProjection r = new DocumentReaderWithProjection(reader, projector);

    assertMapEvent(r, EventType.START_MAP, null);

    assertMapEvent(r, EventType.START_MAP, "k");
    assertMapEvent(r, EventType.START_MAP, "l");
    assertMapEvent(r, EventType.START_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l2");
    assertMapEvent(r, EventType.END_MAP, "l1");
    assertMapEvent(r, EventType.DOUBLE, "l3");
    assertMapEvent(r, EventType.END_MAP, "l");
    assertMapEvent(r, EventType.END_MAP, "k");

    assertMapEvent(r, EventType.END_MAP, null);

    assertNull(r.next());
  }
}
 
开发者ID:ojai,项目名称:ojai,代码行数:26,代码来源:TestDocumentReaderWithProjection.java


示例19: queryByAge

import org.ojai.DocumentStream; //导入依赖的package包/类
private void queryByAge() {

    QueryCondition condition = MapRDB.newCondition()
            .is("age", QueryCondition.Op.GREATER , 50)
            .build();

    int counter = 0;
    try(DocumentStream documentStream = table.find(condition)) {
      for (Document doc : documentStream ) {
        System.out.print(".");
        counter++;
      }
    }
    System.out.println("\n\nTotal documents : "+ counter + " for "+ condition);

  }
 
开发者ID:mapr-demos,项目名称:maprdb-ojai-101,代码行数:17,代码来源:Ex04MultipleDocumentsQuery.java


示例20: recordCount

import org.ojai.DocumentStream; //导入依赖的package包/类
private int recordCount() {
  Table tab;
  try {
    tab = MapRDB.getTable(TABLE_NAME);
    DocumentStream stream = tab.find();
    Iterator<Document> iter = stream.iterator();
    int i = 0 ;
    while(iter.hasNext()) {
      iter.next();    // don't care about the returned Document.
      i++;
    }
    tab.close();
    return i;

  } catch (DBException ex) {
    throw ex;
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:19,代码来源:MapRJsonTargetIT.java



注:本文中的org.ojai.DocumentStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Channel类代码示例发布时间:2022-05-22
下一篇:
Java ProgressMonitor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap