当前位置: 首页>>代码示例>>Java>>正文


Java DocumentStream类代码示例

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


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


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