Examples of KijiTable


Examples of org.kiji.schema.KijiTable

        LOG.info(String.format("  Populating existing table: %s", tableName));
      } else {
        LOG.info(String.format("  Creating and populating table: %s", tableName));
        kiji.createTable(layout.getDesc());
      }
      final KijiTable kijiTable = kiji.openTable(tableName);
      try {
        final KijiTableWriter writer = kijiTable.openTableWriter();
        try {
          // Build & write rows to the table.
          for (Map.Entry<EntityId, Map<String, Map<String, Map<Long, Object>>>> rowEntry
              : table.entrySet()) {
            final EntityId entityId = rowEntry.getKey();
            final Map<String, Map<String, Map<Long, Object>>> row = rowEntry.getValue();
            for (Map.Entry<String, Map<String, Map<Long, Object>>> familyEntry : row.entrySet()) {
              final String familyName = familyEntry.getKey();
              final Map<String, Map<Long, Object>> family = familyEntry.getValue();
              for (Map.Entry<String, Map<Long, Object>> qualifierEntry : family.entrySet()) {
                final String qualifierName = qualifierEntry.getKey();
                final Map<Long, Object> qualifier = qualifierEntry.getValue();
                for (Map.Entry<Long, Object> valueEntry : qualifier.entrySet()) {
                  final long timestamp = valueEntry.getKey();
                  final Object value = valueEntry.getValue();
                  LOG.info("\tBuilding put: {} -> ({}:{}, {}:{})",
                      entityId, familyName, qualifierName, timestamp, value);
                  writer.put(entityId, familyName, qualifierName, timestamp, value);
                }
              }
            }
          }
        } finally {
          writer.close();
        }
      } finally {
        kijiTable.release();
      }
    }

    // Add the Kiji instance to the environment.
    return kiji;
View Full Code Here

Examples of org.kiji.schema.KijiTable

                .withFamily("family")
                    .withQualifier("column")
                        .withValue("0123456789")
        .build();

    final KijiTable table = kiji.openTable("table");
    try {
      final EntityId eid = table.getEntityId("row");

      final KijiTableLayout layout = table.getLayout();
      final KijiColumnName column = KijiColumnName.create("family", "column");
      final Map<KijiColumnName, CellSpec> overrides =
          ImmutableMap.<KijiColumnName, CellSpec>builder()
          .put(column, layout.getCellSpec(column)
              .setCellSchema(CellSchema.newBuilder()
                  .setType(SchemaType.INLINE)
                  .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

Examples of org.kiji.schema.KijiTable

                        .withValue(2L, "name2")
                    .withQualifier("email")
                        .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

Examples of org.kiji.schema.KijiTable

  @Test
  public void testStripValueRowFilter() throws Exception {
    final Kiji kiji = getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));

    final KijiTable table = kiji.openTable("table");
    try {
      final EntityId eid = table.getEntityId("eid");

      {
        final KijiTableWriter writer = table.openTableWriter();
        try {
          writer.put(eid, "family", "column", 1L, "me");
          writer.put(eid, "family", "column", 2L, "me-too");
        } 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

Examples of org.kiji.schema.KijiTable

  /** Tests writer schema registration with no reader schema, ie. no constraint. */
  @Test
  public void testNoReaderSchema() throws Exception {
    final Kiji kiji = getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(LAYOUT_DEVELOPER));
    final KijiTable table = kiji.openTable("dev");
    try {
      final EntityId eid = table.getEntityId("row");
      final KijiTableWriter writer = table.getWriterFactory().openTableWriter();
      try {
        // Registers writer schema 'long':
        writer.put(eid, "info", "user_id", (Long) 1L);

        // Should not need to register writer schema 'long':
        {
          final String layoutIdBefore = table.getLayout().getDesc().getLayoutId();
          writer.put(eid, "info", "user_id", (Long) 2L);
          final String layoutIdAfter = table.getLayout().getDesc().getLayoutId();
          Assert.assertEquals(layoutIdBefore, layoutIdAfter);
        }

        // Register writer schema 'string':
        writer.put(eid, "info", "user_id", "string");

        // Register writer schema for TestRecord1:
        final TestRecord1 record1 = TestRecord1.newBuilder().setInteger(314).build();
        writer.put(eid, "info", "user_id", record1);
      } finally {
        writer.close();
      }

      final List<AvroSchema> expectedIds = Lists.newArrayList(
          AvroSchema.newBuilder()
              .setUid(kiji.getSchemaTable().getOrCreateSchemaId(SCHEMA_LONG))
              .build(),
          AvroSchema.newBuilder()
              .setUid(kiji.getSchemaTable().getOrCreateSchemaId(SCHEMA_STRING))
              .build(),
          AvroSchema.newBuilder()
              .setUid(kiji.getSchemaTable().getOrCreateSchemaId(TestRecord1.SCHEMA$))
              .build());

      final List<AvroSchema> writerSchemaIds =
          table.getLayout().getCellSchema(KijiColumnName.create("info:user_id")).getWriters();
      Assert.assertEquals(expectedIds, writerSchemaIds);

      final List<AvroSchema> writtenSchemaIds =
          table.getLayout().getCellSchema(KijiColumnName.create("info:user_id")).getWritten();
      Assert.assertEquals(expectedIds, writtenSchemaIds);

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

Examples of org.kiji.schema.KijiTable

        AvroSchema.newBuilder()
            .setUid(kiji.getSchemaTable().getOrCreateSchemaId(SCHEMA_LONG))
            .build()));

    kiji.createTable(desc);
    final KijiTable table = kiji.openTable("dev");
    try {
      final EntityId eid = table.getEntityId("row");
      final KijiTableWriter writer = table.getWriterFactory().openTableWriter();
      try {
        // Registering 'long' as a writer schema: compatible with 'long' reader schema:
        writer.put(eid, "info", "user_id", (Long) 1L);

        // Should not require additional registration:
        {
          final String layoutIdBefore = table.getLayout().getDesc().getLayoutId();
          writer.put(eid, "info", "user_id", (Long) 2L);
          final String layoutIdAfter = table.getLayout().getDesc().getLayoutId();
          Assert.assertEquals(layoutIdBefore, layoutIdAfter);
        }

        // Registering 'int' as a writer schema: compatible with 'long' reader schema:
        writer.put(eid, "info", "user_id", (Integer) 1);

        // Register writer schema 'string' must fail: incompatible with 'long':
        try {
          writer.put(eid, "info", "user_id", "1");
          Assert.fail("Registering writer schema 'string' should fail.");
        } catch (InvalidLayoutSchemaException ilse) {
          LOG.info("Expected error: {}", ilse.toString());
          Assert.assertTrue(ilse.toString().contains(
              "column: 'info:user_id' "
              + "Reader schema: \"long\" is incompatible with writer schema: \"string\""));
        }
      } finally {
        writer.close();
      }

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

Examples of org.kiji.schema.KijiTable

        AvroSchema.newBuilder()
            .setUid(kiji.getSchemaTable().getOrCreateSchemaId(INT_TEXT_RECORD1))
            .build()));

    kiji.createTable(desc);
    final KijiTable table = kiji.openTable("dev");
    try {
      final EntityId eid = table.getEntityId("row");
      final KijiTableWriter writer = table.getWriterFactory().openTableWriter();
      try {
        // Register writer schema TestRecord1, compatible with reader TestRecord2:
        final GenericData.Record record1 = new GenericData.Record(INT_RECORD1);
        record1.put("integer", 314);
        writer.put(eid, "info", "user_id", record1);

        // Register writer schema TestRecord2, is exactly reader TestRecord2:
        final GenericData.Record record2 = new GenericData.Record(INT_TEXT_RECORD1);
        record2.put("integer", 314);
        record2.put("text", "text");
        writer.put(eid, "info", "user_id", record2);

        // Register writer schema TestRecord3, compatible with reader TestRecord2:
        final GenericData.Record record3 = new GenericData.Record(INT_ANOTHER_TEXT_RECORD1);
        record3.put("integer", 314);
        record3.put("another_text", "text");
        writer.put(eid, "info", "user_id", record3);

        // Any primitive type is incompatible with reader schema TestRecord1:
        try {
          writer.put(eid, "info", "user_id", "1");
          Assert.fail("Registering writer schema 'string' should fail.");
        } catch (InvalidLayoutSchemaException ilse) {
          LOG.info("Expected error: {}", ilse.toString());
          Assert.assertTrue(
              ilse.getMessage(),
              ilse.getMessage().contains("In column: 'info:user_id'"));
          Assert.assertTrue(
              ilse.getMessage(),
              ilse.getMessage().contains("is incompatible with writer schema"));
        }

      } finally {
        writer.close();
      }

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

Examples of org.kiji.schema.KijiTable

            .withRow("row2")
                .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

Examples of org.kiji.schema.KijiTable

  @Test
  public void testScanTable() throws Exception {
    final Kiji kiji = getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));
    final KijiTable table = kiji.openTable("table");
    try {
      // Table is empty:
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString()));
      assertEquals(1, mToolOutputLines.length);
      assertTrue(mToolOutputLines[0].startsWith("Scanning kiji table: "));

      new InstanceBuilder(kiji)
          .withTable(table)
              .withRow("hashed")
                  .withFamily("family").withQualifier("column").withValue(314L, "value")
          .build();

      // Table has now one row:
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString()));
      assertEquals(3, mToolOutputLines.length);
      assertTrue(mToolOutputLines[0].startsWith("Scanning kiji table: "));
      assertTrue(mToolOutputLines[1].startsWith("entity-id=hbase=hex:"));

    } finally {
View Full Code Here

Examples of org.kiji.schema.KijiTable

  @Test
  public void testTableColumns() throws Exception {
    final Kiji kiji = getKiji();
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE);
    kiji.createTable(layout.getDesc());
    final KijiTable table = kiji.openTable(layout.getName());
    try {
      // Table is empty:
      assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), table.getURI().toString()));
      assertEquals(1, mToolOutputLines.length);
      assertTrue(mToolOutputLines[0].contains("family:column"));
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.