Package org.kiji.schema

Examples of org.kiji.schema.Kiji


  private static final CassandraKijiClientTest CLIENT_TEST_DELEGATE = new CassandraKijiClientTest();

  @BeforeClass
  public static void initShared() throws Exception {
    CLIENT_TEST_DELEGATE.setupKijiTest();
    Kiji kiji = CLIENT_TEST_DELEGATE.getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(KijiTableLayouts.TTL_TEST));
    mTable = kiji.openTable("ttl_test");
  }
View Full Code Here


  private KijiTableKeyValueDatabase mDb;

  @Before
  public final void setupTable() throws IOException {
    // This will install a new Kiji instance.
    final Kiji kiji = getKiji();

    // Get an admin and create a table for this instance.
    KijiURI kijiURI = kiji.getURI();
    //mAdmin = CassandraFactory
        //.Provider
        //.get()
        //.getCassandraAdminFactory(kijiURI)
        //.create(kijiURI);

    // Fill it with some data.
    mDb = kiji.getMetaTable();
    mDb.putValue("table1", "config1", Bytes.toBytes("1one"));
    mDb.putValue("table1", "config2", Bytes.toBytes("1two"));
    mDb.putValue("table2", "config1", Bytes.toBytes("2one"));
    mDb.putValue("table2", "config2", Bytes.toBytes("2two"));
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  protected int run(final List<String> nonFlagArgs) throws Exception {
    final Kiji kiji = Kiji.Factory.open(mURI);
    try {
      final KijiTable table = kiji.openTable(mURI.getTable());
      try {
        mAnnotator = table.openTableAnnotator();
        try {
          switch (mDoMode) {
            case SET: return set();
            case REMOVE: return remove();
            case GET: return get();
            default: throw new InternalKijiError("Unknown NotesTool DoMode: " + mDoMode);
          }
        } finally {
          mAnnotator.close();
        }
      } finally {
        table.release();
      }
    } finally {
      kiji.release();
    }
  }
View Full Code Here

  private static final byte[] BYTES_VALUE = Bytes.toBytes("value");

  @Test
  public void testBackupAndRestore() throws InterruptedException, IOException {
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();
    final KijiSchemaTable schemaTable = kiji.getSchemaTable();
    final KijiSystemTable systemTable = kiji.getSystemTable();

    // Update the layout for table foo.
    final TableLayoutDesc layout =
        KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST_FORMATTED_EID);
    final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);

    // Insert a user-level key-value pair for table foo.
    metaTable.putValue("foo", "key", BYTES_VALUE);

    // Insert a key-value pair in the system table
    systemTable.putValue("testKey", Bytes.toBytes("testValue"));

    // The meta table should have a single table, foo, in it.
    assertEquals(1, metaTable.listTables().size());
    assertEquals(1, metaTable.tableSet().size());

    // The meta table should have a single key-value pair, "key"/"value", for table foo.
    assertEquals(1, metaTable.keySet("foo").size());
    assertArrayEquals(BYTES_VALUE, metaTable.getValue("foo", "key"));

    // write to backupBuilder
    final MetadataBackup.Builder backupBuilder = MetadataBackup.newBuilder()
        .setLayoutVersion(kiji.getSystemTable().getDataVersion().toString())
        .setMetaTable(
            MetaTableBackup.newBuilder()
                .setTables(new HashMap<String, TableBackup>())
                .build())
        .setSchemaTable(
            SchemaTableBackup.newBuilder()
                .setEntries(new ArrayList<SchemaTableEntry>())
                .build())
        .setSystemTable(
            SystemTableBackup.newBuilder()
                .setEntries(new ArrayList<SystemTableEntry>())
                .build());
    backupBuilder.setMetaTable(metaTable.toBackup());
    backupBuilder.setSchemaTable(schemaTable.toBackup());
    backupBuilder.setSystemTable(systemTable.toBackup());
    final MetadataBackup backup = backupBuilder.build();

    // make sure metadata key-value pairs are what we expect.
    List<KeyValueBackupEntry> keyValues =
        backup.getMetaTable().getTables().get("foo").getKeyValueBackup().getKeyValues();
    assertEquals(1, keyValues.size());
    assertEquals("key", keyValues.get(0).getKey());
    assertArrayEquals(BYTES_VALUE, keyValues.get(0).getValue().array());

    // make sure layouts are what we expect.
    List<TableLayoutBackupEntry> layoutBackups =
        backup.getMetaTable().getTables().get("foo").getTableLayoutsBackup().getLayouts();
    assertEquals(1, layoutBackups.size());
    assertEquals(updatedLayout.getDesc(), layoutBackups.get(0).getLayout());

    // Delete the entries for "foo" from the meta table.
    metaTable.deleteTable("foo");
    assertTrue(!metaTable.tableSet().contains("foo"));
    LOG.info("metaTable tables = " + metaTable.listTables());
    assertEquals(0, metaTable.listTables().size());
    assertEquals(0, metaTable.tableSet().size());

    final CassandraMetadataRestorer restorer = new CassandraMetadataRestorer();
    restorer.restoreTables(backup, kiji);

    final KijiMetaTable newMetaTable = kiji.getMetaTable();
    assertEquals("The number of tables with layouts is incorrect.", 1,
        newMetaTable.listTables().size());
    assertEquals("The number of tables with kv pairs is incorrect.", 1,
        newMetaTable.tableSet().size());
    assertEquals("The number of keys for the foo table is incorrect.", 1,
View Full Code Here

    assertEquals("testValue", Bytes.toString(systemTable.getValue("testKey")));
  }

  @Test
  public void testSameMetaTableOnPut() throws InterruptedException, IOException {
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();

    final KijiTableKeyValueDatabase<?> outDb = metaTable.putValue("foo", "key", BYTES_VALUE);
    assertEquals("putValue() exposes the delegate", metaTable, outDb);
  }
View Full Code Here

  @Test
  public void testChainedMetaTable() throws InterruptedException, IOException {
    // Do an operation on the metatable, then set a key with putValue().
    // Use the KijiMetaTable obj returned by this to modify the underlying db.
    // Verify that the original KijiMetaTable sees the change.
    final Kiji kiji = getKiji();
    final KijiMetaTable metaTable = kiji.getMetaTable();

    final TableLayoutDesc layout =
        KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST_FORMATTED_EID);
    final KijiTableLayout updatedLayout = metaTable.updateTableLayout("foo", layout);
View Full Code Here

  private KijiTableWriter mWriter;

  @BeforeClass
  public static void initShared() throws Exception {
    CLIENT_TEST_DELEGATE.setupKijiTest();
    Kiji kiji = CLIENT_TEST_DELEGATE.getKiji();
    kiji.createTable(KijiTableLayouts.getLayout(TEST_LAYOUT_V1));
    mTable = kiji.openTable(TABLE_NAME);
  }
View Full Code Here

      getPrintStream().printf("--timestamp must be like [0-9]*..[0-9]*, instead got %s%n",
          mTimestamp);
      return FAILURE;
    }

    final Kiji kiji = Kiji.Factory.open(argURI, getConf());
    try {
      final KijiTable table = kiji.openTable(argURI.getTable());
      try {
        final KijiTableLayout tableLayout = table.getLayout();

        final Map<FamilyLayout, List<String>> mapTypeFamilies =
            ToolUtils.getMapTypeFamilies(argURI.getColumns(), tableLayout);

        final Map<FamilyLayout, List<ColumnLayout>> groupTypeColumns =
            ToolUtils.getGroupTypeColumns(argURI.getColumns(), tableLayout);

        final KijiDataRequest request = ToolUtils.getDataRequest(
            mapTypeFamilies, groupTypeColumns, mMaxVersions, mMinTimestamp, mMaxTimestamp);

        final KijiTableReader reader = table.openTableReader();
        try {
            // Return the specified entity.
            final EntityId entityId =
                ToolUtils.createEntityIdFromUserInputs(mEntityIdFlag, tableLayout);
            // TODO: Send this through an alternative stream: something like verbose or debug?
            getPrintStream().println(
                "Looking up entity: " + ToolUtils.formatEntityId(entityId)
                + " from kiji table: " + argURI);
            return lookup(reader, request, entityId, mapTypeFamilies, groupTypeColumns);
        } finally {
          reader.close();
        }
      } finally {
        table.release();
      }
    } finally {
      kiji.release();
    }
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  protected int run(List<String> nonFlagArgs) throws Exception {
    final Kiji kiji = Kiji.Factory.open(mCellURI, getConf());
    try {
      final KijiTable table = kiji.openTable(mCellURI.getTable());
      try {
        final KijiTableWriter writer = table.openTableWriter();
        try {
          for (KijiColumnName column : mCellURI.getColumns()) {
            try {
View Full Code Here

    if (argURI.getInstance() == null) {
      // List instances in this kiji instance.
      return listInstances(argURI);
    }

    final Kiji kiji = Kiji.Factory.open(argURI, getConf());
    try {
      if (argURI.getTable() == null) {
        // List tables in this kiji instance.
        return listTables(kiji);
      }

      final KijiTable table = kiji.openTable(argURI.getTable());
      try {
        final KijiTableLayout tableLayout = table.getLayout();
        for (FamilyLayout family : tableLayout.getFamilies()) {
          if (family.isMapType()) {
            getPrintStream().println(KijiURI.newBuilder(table.getURI())
View Full Code Here

TOP

Related Classes of org.kiji.schema.Kiji

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.