Package org.kiji.schema

Examples of org.kiji.schema.KijiTableReader


                  .add(pets, rabbit)
                  .add(pets, fish)
                  .add(pets, bird)
          ).build();

      final KijiTableReader myreader = table.openTableReader();
      assert myreader instanceof CassandraKijiTableReader;
      final CassandraKijiTableReader reader = (CassandraKijiTableReader) myreader;

      try {
        // Fire up a row scanner!
View Full Code Here


                  .add(pets, rabbit)
                  .add(pets, fish)
                  .add(pets, bird)
          ).build();

      final KijiTableReader reader = table.openTableReader();
      try {
        // Fire up a row scanner!
        final KijiRowScanner scanner = reader.getScanner(dataRequest);
        try {
          // There is a small enough amount of data that we can just put all of the rows into a hash
          // from entity ID to row data.
          HashMap<EntityId, KijiRowData> allData = new HashMap<EntityId, KijiRowData>();

          for (KijiRowData row : scanner) {
            EntityId eid = row.getEntityId();
            assert (!allData.containsKey(eid));
            allData.put(eid, row);
          }

          assertTrue(allData.containsKey(alice));
          assertTrue(allData.containsKey(bob));
          assertTrue(allData.containsKey(cathy));
          assertTrue(allData.containsKey(david));

          assertTrue(allData.get(alice).containsColumn(pets, cat));
          assertTrue(allData.get(alice).containsColumn(pets, dog));
          assertFalse(allData.get(alice).containsColumn(pets, rabbit));
          assertFalse(allData.get(alice).containsColumn(pets, fish));
          assertFalse(allData.get(alice).containsColumn(pets, bird));

          assertTrue(allData.get(bob).containsColumn(pets, cat));
          assertTrue(allData.get(bob).containsColumn(pets, rabbit));
          assertFalse(allData.get(bob).containsColumn(pets, dog));
          assertFalse(allData.get(bob).containsColumn(pets, fish));
          assertFalse(allData.get(bob).containsColumn(pets, bird));

          assertTrue(allData.get(cathy).containsColumn(pets, cat));
          assertTrue(allData.get(cathy).containsColumn(pets, fish));
          assertFalse(allData.get(cathy).containsColumn(pets, dog));
          assertFalse(allData.get(cathy).containsColumn(pets, rabbit));
          assertFalse(allData.get(cathy).containsColumn(pets, bird));

          assertTrue(allData.get(david).containsColumn(pets, cat));
          assertTrue(allData.get(david).containsColumn(pets, bird));
          assertFalse(allData.get(david).containsColumn(pets, dog));
          assertFalse(allData.get(david).containsColumn(pets, rabbit));
          assertFalse(allData.get(david).containsColumn(pets, fish));
        } finally {
          scanner.close();
        }
      } finally {
        reader.close();
      }
    } finally {
      table.release();
    }
  }
View Full Code Here

        tableWriter.close();
      }

      // ----- Read a row from the table. -----
      // Get a TableReader for our table.
      KijiTableReader tableReader = table.openTableReader();
      // Surround with a try/finally so the tablereader gets closed.
      try {
        // Build a DataRequest for the row we want.
        KijiDataRequest dataRequest = KijiDataRequest.create("info", "name");
        KijiRowData result = tableReader.get(entityId, dataRequest);
        String name = result.getMostRecentValue("info", "name").toString();
        System.out.println("Read username " + name + " from table.");
      } finally {
        tableReader.close();
      }
    } finally {
      kiji.release();
    }
  }
View Full Code Here

                  .setStorage(SchemaStorage.FINAL)
                  .setValue("{\"type\": \"fixed\", \"size\": 4, \"name\": \"Int32\"}")
                  .build()))
          .build();

      final KijiTableReader reader = table.getReaderFactory().openTableReader(overrides);
      try {
        final KijiDataRequest dataRequest = KijiDataRequest.builder()
            .addColumns(ColumnsDef.create().withFilter(new CellByteSizeAsValueFilter()).add(column))
            .build();
        final KijiRowData row = reader.get(eid, dataRequest);
        final GenericData.Fixed fixed32 = row.getMostRecentValue("family", "column");
        final int cellSize = Bytes.toInt(fixed32.bytes());

        // Cell size is: length(MD5-hash) + len(string size) + len(string)
        assertEquals(16 + 1 + 10, cellSize);

      } finally {
        reader.close();
      }
    } finally {
      table.release();
    }
  }
View Full Code Here

                        .withValue(1L, "email1")
                        .withValue(2L, "email2")
        .build();
    final KijiTable table = kiji.openTable("user");
    try {
      final KijiTableReader reader = table.openTableReader();
      try {
        final EntityId eid = table.getEntityId("row");

        // Make sure we have 2 versions in columns info:name and in info:email.
        {
          final KijiDataRequest dataRequest = KijiDataRequest.builder()
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .addFamily("info"))
              .build();
          final KijiRowData row = reader.get(eid, dataRequest);
          assertEquals(2, row.getValues("info", "name").size());
          assertEquals(2, row.getValues("info", "email").size());
        }

        // Test FirstKeyOnly filter when applied on the group-type family.
        {
          final KijiDataRequest dataRequest = KijiDataRequest.builder()
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .withFilter(new KijiFirstKeyOnlyColumnFilter())
                  .addFamily("info"))
              .build();
          final KijiRowData row = reader.get(eid, dataRequest);
          assertEquals(1, row.getValues("info", "name").size());
          assertEquals(1, row.getValues("info", "email").size());
        }

        // Test FirstKeyOnly filter when applied on a single column.
        // Make sure it doesn't affect other columns.
        {
          final KijiDataRequest dataRequest = KijiDataRequest.builder()
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .withFilter(new KijiFirstKeyOnlyColumnFilter())
                  .add("info", "name"))
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .add("info", "email"))
              .build();
          final KijiRowData row = reader.get(eid, dataRequest);
          assertEquals(1, row.getValues("info", "name").size());
          assertEquals(2, row.getValues("info", "email").size());
        }

        // Test FirstKeyOnly filter when applied on a single column.
        // Make sure it doesn't affect other columns.
        {
          final KijiDataRequest dataRequest = KijiDataRequest.builder()
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .add("info", "name"))
              .addColumns(ColumnsDef.create()
                  .withMaxVersions(HConstants.ALL_VERSIONS)
                  .withFilter(new KijiFirstKeyOnlyColumnFilter())
                  .add("info", "email"))
              .build();
          final KijiRowData row = reader.get(eid, dataRequest);
          assertEquals(2, row.getValues("info", "name").size());
          assertEquals(1, row.getValues("info", "email").size());
        }

      } finally {
        reader.close();
      }
    } finally {
      table.release();
    }
  }
View Full Code Here

        } finally {
          writer.close();
        }
      }

      final KijiTableReader reader = table.openTableReader();
      try {
        final KijiDataRequest dataRequest = KijiDataRequest.builder()
            .addColumns(ColumnsDef.create().withMaxVersions(2).add("family", "column"))
            .build();
        final KijiRowFilter rowFilter = new StripValueRowFilter();
        final KijiScannerOptions scannerOptions =
            new KijiScannerOptions().setKijiRowFilter(rowFilter);

        final KijiRowScanner scanner = reader.getScanner(dataRequest, scannerOptions);
        try {
          for (KijiRowData row : scanner) {
            final NavigableSet<String> qualifiers = row.getQualifiers("family");
            assertEquals(1, qualifiers.size());
            assertTrue(qualifiers.contains("column"));

            // Ensure that we can use getTimestamps() to count.
            assertEquals(2, row.getTimestamps("family", "column").size());
            try {
              // Cell value is stripped, hence IOException on the wrong schema hash:
              row.getMostRecentValue("family", "column");
              fail("row.getMostRecentValue() did not throw IOException.");
            } catch (IOException ioe) {
              assertTrue(ioe.getMessage(),
                  ioe.getMessage().contains(
                      "Schema with hash 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 "
                      + "not found in schema table."));
            }
          }
        } finally {
          scanner.close();
        }
      } finally {
        reader.close();
      }
    } finally {
      table.release();
    }
  }
View Full Code Here

                .withFamily("family")
                    .withQualifier("column").withValue(100, "foo3")
        .build();

    final KijiTable table = kiji.openTable("table");
    final KijiTableReader reader = table.openTableReader();

    // Verify the first row.
    final KijiDataRequest req = KijiDataRequest.create("family", "column");
    final KijiRowData row1 = reader.get(table.getEntityId("row1"), req);
    assertEquals("foo2", row1.getValue("family", "column", 2).toString());

    // Verify the second row.
    final KijiRowData row2 = reader.get(table.getEntityId("row2"), req);
    assertEquals("foo3", row2.getValue("family", "column", 100).toString());

    ResourceUtils.closeOrLog(reader);
    ResourceUtils.releaseOrLog(table);
  }
View Full Code Here

    final String expected = "expected";
    Assert.assertEquals(expected, new WithKijiTableWriter<String>(mTable.getURI()) {
      @Override
      public String run(final KijiTableWriter kijiTableWriter) throws Exception {
        kijiTableWriter.put(mTable.getEntityId("bar"), "family", "qual0", expected);
        final KijiTableReader reader = mTable.openTableReader();
        try {
          return reader.get(
              mTable.getEntityId("bar"),
              FAMILY_QUAL0_R
          ).getMostRecentValue("family", "qual0").toString();
        } finally {
          reader.close();
        }
      }
    }.eval());

    Assert.assertEquals(expected, new WithKijiTableWriter<String>(mTable) {
      @Override
      public String run(final KijiTableWriter kijiTableWriter) throws Exception {
        kijiTableWriter.put(mTable.getEntityId("bar"), "family", "qual0", expected);
        final KijiTableReader reader = mTable.openTableReader();
        try {
          return reader.get(
              mTable.getEntityId("bar"),
              FAMILY_QUAL0_R
          ).getMostRecentValue("family", "qual0").toString();
        } finally {
          reader.close();
        }
      }
    }.eval());
  }
View Full Code Here

    kiji.createTable(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE_FORMATTED_EID));
    KijiTable mTable = kiji.openTable("table");
    try {
      assertNotNull(mTable);
      // Fill local variables.
      KijiTableReader mReader = mTable.openTableReader();
      try {
        KijiTableWriter mWriter = mTable.openTableWriter();
        try {
          EntityId mEntityId = mTable.getEntityId("eid-foo");

          mWriter.put(mEntityId, "family", "column", 0L, "Value at timestamp 0.");
          mWriter.put(mEntityId, "family", "column", 1L, "Value at timestamp 1.");

          final KijiDataRequest dataRequest = KijiDataRequest.builder()
              .addColumns(
                  KijiDataRequestBuilder.ColumnsDef.create()
                      .withMaxVersions(2)
                      .add("family", "column"))
              .build();

          // Try this as a get.
          KijiRowData rowData = mReader.get(mEntityId, dataRequest);
          String s = rowData.getValue("family", "column", 0L).toString();
          assertEquals(s, "Value at timestamp 0.");

          // Delete the cell and make sure that this value is missing.
          mWriter.deleteCell(mEntityId, "family", "column", 0L);

          rowData = mReader.get(mEntityId, dataRequest);
          assertFalse(rowData.containsCell("family", "column", 0L));
        } finally {
          mWriter.close();
        }
      } finally {
        mReader.close();
      }
    } finally {
      mTable.release();
    }
  }
View Full Code Here

        .add(EMPTY, ColumnReaderSpec.avroReaderSchemaSpecific(TestRecord1.class))).build();

    final KijiTable table = getKiji().openTable("table");
    try {
      final EntityId eid = table.getEntityId("row");
      final KijiTableReader reader = table.openTableReader();
      try {
        final KijiRowData normalData = reader.get(eid, normalRequest);
        final EmptyRecord emptyRecord = normalData.getMostRecentValue("family", "empty");

        final KijiRowData overrideData = reader.get(table.getEntityId("row"), overrideRequest);
        final TestRecord1 record1 = overrideData.getMostRecentValue("family", "empty");
        assertEquals(Integer.valueOf(-1), record1.getInteger());
      } finally {
        reader.close();
      }
    } finally {
      table.release();
    }
  }
View Full Code Here

TOP

Related Classes of org.kiji.schema.KijiTableReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.