Package org.kiji.schema

Examples of org.kiji.schema.Kiji$Factory


    // This is the default kiji instance.
    final String uri = "kiji://.env/default";
    final KijiURI kijiURI = KijiURI.newBuilder(uri).build();

    // Open the kiji specified.
    Kiji kiji = Kiji.Factory.open(kijiURI);

    // Always surround with a try {} finally{} so the kiji gets released,
    // no matter what happens.
    try {
      // ----- Create a kiji table. -----
      // First, we need to create a table layout.
      final KijiTableLayout layout =
        KijiTableLayout.newLayout(
          KijiTableLayout.readTableLayoutDescFromJSON(
              new FileInputStream(tableDesc)));

      // Create the kiji table.
      kiji.createTable(tableName, layout);
      // Get a handle to the table.
      KijiTable table = kiji.openTable(tableName);

      // Get the entity ID, according to this table, of the user we are
      // demonstrating with.
      EntityId entityId = table.getEntityId(userId);

      // ----- Write a row to the table. -----
      // Get a TableWriter for our table.
      KijiTableWriter tableWriter = table.openTableWriter();
      // Surround with a try/finally so the tablewriter gets closed.
      try {
        System.out.println("Putting user " + username + " into table.");
        tableWriter.put(entityId, "info", "name", username);
        // Flush the write to the table, since this is a demo and
        // we are not concerned about efficiency, we just want to
        // show that the cell got written successfully.
        tableWriter.flush();
      } finally {
        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


      LOG.info(String.format("Installing kiji instance '%s'.", uri));
      HBaseSystemTable.install(hbaseAdmin, uri, conf, properties, tableFactory);
      HBaseMetaTable.install(hbaseAdmin, uri);
      HBaseSchemaTable.install(hbaseAdmin, uri, conf, tableFactory);
      // Grant the current user all privileges on the instance just created, if security is enabled.
      final Kiji kiji = Kiji.Factory.open(uri, conf);
      try {
        if (kiji.isSecurityEnabled()) {
          KijiSecurityManager.Installer.installInstanceCreator(uri, conf, tableFactory);
        }
      } finally {
        kiji.release();
      }
    } finally {
      ResourceUtils.closeOrLog(hbaseAdmin);
    }
    LOG.info(String.format("Installed kiji instance '%s'.", uri));
View Full Code Here

  private static final Schema SCHEMA_NULL = Schema.create(Schema.Type.NULL);

  /** Tests expansion of a writer schema union { null, string }. */
  @Test
  public void testUnionWriterSchema() throws Exception {
    final Kiji kiji = getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(LAYOUT_UNION_WRITER));
    final KijiTable table = kiji.openTable(TABLE_NAME);
    try {
      final EntityId eid = table.getEntityId("row");
      final KijiTableWriter writer = table.getWriterFactory().openTableWriter();
      try {
        // Writing naked type "null" should work:
        writer.put(eid, "info", "user", null);

        // Writing naked type "string" should work too:
        writer.put(eid, "info", "user", "a string");

        final Schema unionNullString =
            Schema.createUnion(Lists.newArrayList(SCHEMA_NULL, SCHEMA_STRING));
        final List<AvroSchema> expectedIds = Lists.newArrayList(
            AvroSchema.newBuilder()
                .setUid(kiji.getSchemaTable().getOrCreateSchemaId(unionNullString))
                .build());

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

  }

  /** Tests behavior of Avro enums. */
  @Test
  public void testEnumSchema() throws Exception {
    final Kiji kiji = getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(LAYOUT_ENUM));

    final Schema readerEnum =
        Schema.createEnum("Gender", null, null, ImmutableList.of("MALE", "FEMALE"));
    final Schema writerEnum =
        Schema.createEnum("Gender", null, null, ImmutableList.of("MALE", "FEMALE", "BOTH"));

    final KijiTable table = kiji.openTable(TABLE_NAME);
    try {

      final TableLayoutDesc updateWithReader =
          new TableLayoutBuilder(table.getLayout().getDesc(), kiji)
              .withReader(KijiColumnName.create("info""gender"), readerEnum)
              .build();
      LOG.debug("Applying update with enum reader: %s", updateWithReader);
      kiji.modifyTableLayout(updateWithReader);

      final TableLayoutDesc updateWithWriter=
          new TableLayoutBuilder(table.getLayout().getDesc(), kiji)
              .withWriter(KijiColumnName.create("info""gender"), writerEnum)
              .build();
      LOG.debug("Applying update with enum writer: %s", updateWithWriter);
      try {
        kiji.modifyTableLayout(updateWithWriter);
        Assert.fail();
      } catch (InvalidLayoutSchemaException ilse) {
        LOG.debug("Expected error: {}", ilse.getMessage());
        Assert.assertTrue(
            ilse.getMessage(),
View Full Code Here

        KijiInstaller.get().install(uri, conf);
      }
    } catch (KijiInvalidNameException kine) {
      throw new IOException(kine);
    }
    final Kiji kiji = (mExistingKiji != null)
        ? mExistingKiji
        : Kiji.Factory.open(uri, conf);

    // Build tables.
    for (Map.Entry<String, Map<EntityId, Map<String, Map<String, Map<Long, Object>>>>> tableEntry
        : mCells.entrySet()) {
      final String tableName = tableEntry.getKey();
      final KijiTableLayout layout = mLayouts.get(tableName);
      final Map<EntityId, Map<String, Map<String, Map<Long, Object>>>> table =
          tableEntry.getValue();

      // Create & open a Kiji table.
      if (kiji.getTableNames().contains(tableName)) {
        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
View Full Code Here

public class TestSystemTableTool extends KijiToolTest {
  private static final Logger LOG = LoggerFactory.getLogger(TestSystemTableTool.class);

  @Test
  public void testGetAll() throws Exception {
    final Kiji kiji = getKiji();
    kiji.getSystemTable().putValue("testKey", Bytes.toBytes("testValue"));
    final SystemTableTool st = new SystemTableTool();
    assertEquals(Bytes.toString(kiji.getSystemTable().getValue("testKey")), "testValue");

    assertEquals(BaseTool.SUCCESS, runTool(st, "--kiji=" + kiji.getURI(), "--do=get-all"));
    assertTrue(mToolOutputStr.startsWith("Listing all system table properties:"));
    assertTrue(mToolOutputStr.contains("data-version = "
        + kiji.getSystemTable().getDataVersion().toString()));
    assertTrue(mToolOutputStr, mToolOutputStr.contains("testKey = testValue"));
  }
View Full Code Here

    assertTrue(mToolOutputStr, mToolOutputStr.contains("testKey = testValue"));
  }

  @Test
  public void testGet() throws Exception {
    final Kiji kiji = getKiji();
    kiji.getSystemTable().putValue("testGetKey", Bytes.toBytes("testGetValue"));
    final SystemTableTool st = new SystemTableTool();

    assertEquals(BaseTool.SUCCESS, runTool(
        st, "--kiji=" + kiji.getURI(), "--do=get", "testGetKey"));
    assertEquals(mToolOutputStr.trim(), "testGetKey = testGetValue");
  }
View Full Code Here

    assertEquals(mToolOutputStr.trim(), "testGetKey = testGetValue");
  }

  @Test
  public void testPut() throws Exception {
    final Kiji kiji = getKiji();
    final SystemTableTool st = new SystemTableTool();

    assertEquals(BaseTool.SUCCESS, runTool(
        st, "--kiji=" + kiji.getURI(),
        "--do=put", "testPutKey", "testPutValue", "--interactive=false"));
    assertEquals(
        Bytes.toString(kiji.getSystemTable().getValue("testPutKey")), "testPutValue");
  }
View Full Code Here

        Bytes.toString(kiji.getSystemTable().getValue("testPutKey")), "testPutValue");
  }

  @Test
  public void testGetVersion() throws Exception {
    final Kiji kiji = getKiji();

    final SystemTableTool st = new SystemTableTool();
    assertEquals(BaseTool.SUCCESS, runTool(st, "--kiji=" + kiji.getURI(), "--do=get-version"));
    assertTrue(mToolOutputStr.startsWith("Kiji data version = "));
    assertTrue(mToolOutputStr.contains(kiji.getSystemTable().getDataVersion().toString()));
  }
View Full Code Here

    assertTrue(mToolOutputStr.contains(kiji.getSystemTable().getDataVersion().toString()));
  }

  @Test
  public void testPutVersion() throws Exception {
    final Kiji kiji = getKiji();
    final SystemTableTool st = new SystemTableTool();

    assertEquals(BaseTool.SUCCESS, runTool(
        st, "--kiji=" + kiji.getURI(), "--do=put-version", "system-1.1", "--interactive=false"));
    assertEquals(kiji.getSystemTable().getDataVersion().toString(), "system-1.1");
  }
View Full Code Here

TOP

Related Classes of org.kiji.schema.Kiji$Factory

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.