Examples of KijiTable


Examples of org.kiji.schema.KijiTable

      return true;
    }
    if (!getClass().equals(obj.getClass())) {
      return false;
    }
    final KijiTable other = (KijiTable) obj;

    // Equal if the two tables have the same URI:
    return mTableURI.equals(other.getURI());
  }
View Full Code Here

Examples of org.kiji.schema.KijiTable

  /**
   * Test using a row scanner with a token range.
   */
  @Test
  public void testRowScannerWithTokenRanges() throws Exception {
    final KijiTable table = mKiji.openTable("users");
    try {
      // Reuse these entity IDs for puts and for gets.
      final EntityId alice = table.getEntityId("Alice2");
      final EntityId bob = table.getEntityId("Bob2");
      final EntityId cathy = table.getEntityId("Cathy2");
      final EntityId david = table.getEntityId("David2");

      final String pets = "pets";
      final String cat = "cat";
      final String dog = "dog";
      final String rabbit = "rabbit";
      final String fish = "fish";
      final String bird = "bird";

      final KijiTableWriter writer = table.openTableWriter();
      try {
        // Insert some data into the table.  Give various users different pets.
        writer.put(alice, pets, cat, 0L, "Alister");
        writer.put(bob, pets, cat, 0L, "Buffy");
        writer.put(cathy, pets, cat, 0L, "Mr Cat");
        writer.put(david, pets, cat, 0L, "Dash");

        writer.put(alice, pets, dog, 0L, "Amour");
        writer.put(bob, pets, rabbit, 0L, "Bounce");
        writer.put(cathy, pets, fish, 0L, "Catfish");
        writer.put(david, pets, bird, 0L, "Da Bird");
      } finally {
        writer.close();
      }

      final KijiDataRequest dataRequest = KijiDataRequest.builder()
          .addColumns(
              ColumnsDef
                  .create()
                  .withMaxVersions(100)
                  .add(pets, cat)
                  .add(pets, dog)
                  .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!
        final KijiRowScanner scanner = reader.getScanner(dataRequest);
        try {
          checkScannerResults(
              alice, bob, cathy, david, scanner);
        } finally {
          scanner.close();
        }

        final KijiRowScanner scannerWithStartToken = reader.getScannerWithOptions(
            dataRequest, CassandraKijiScannerOptions.withStartToken(Long.MIN_VALUE));
        try {
          checkScannerResults(
              alice, bob, cathy, david, scannerWithStartToken);
        } finally {
          scannerWithStartToken.close();
        }

        final KijiRowScanner scannerWithStopToken = reader.getScannerWithOptions(
            dataRequest, CassandraKijiScannerOptions.withStopToken(Long.MAX_VALUE));
        try {
          checkScannerResults(
              alice, bob, cathy, david, scannerWithStopToken);
        } finally {
          scannerWithStopToken.close();
        }

        final KijiRowScanner scannerWithTokens = reader.getScannerWithOptions(
            dataRequest, CassandraKijiScannerOptions.withTokens(Long.MIN_VALUE, Long.MAX_VALUE));
        try {
          checkScannerResults(
              alice, bob, cathy, david, scannerWithTokens);
        } finally {
          scannerWithTokens.close();
        }

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

Examples of org.kiji.schema.KijiTable

   * Thus, the `KijiRowScanner` will get back a different `Row` iterator for each unique qualifier,
   * and then have to assemble them back together.
   */
  @Test
  public void testRowScannerSparseData() throws Exception {
    final KijiTable table = mKiji.openTable("users");
    try {

      // Reuse these entity IDs for puts and for gets.
      final EntityId alice = table.getEntityId("Alice");
      final EntityId bob = table.getEntityId("Bob");
      final EntityId cathy = table.getEntityId("Cathy");
      final EntityId david = table.getEntityId("David");

      final String pets = "pets";
      final String cat = "cat";
      final String dog = "dog";
      final String rabbit = "rabbit";
      final String fish = "fish";
      final String bird = "bird";

      final KijiTableWriter writer = table.openTableWriter();
      try {
        // Insert some data into the table.  Give various users different pets.
        writer.put(alice, pets, cat, 0L, "Alister");
        writer.put(bob, pets, cat, 0L, "Buffy");
        writer.put(cathy, pets, cat, 0L, "Mr Cat");
        writer.put(david, pets, cat, 0L, "Dash");

        writer.put(alice, pets, dog, 0L, "Amour");
        writer.put(bob, pets, rabbit, 0L, "Bounce");
        writer.put(cathy, pets, fish, 0L, "Catfish");
        writer.put(david, pets, bird, 0L, "Da Bird");
      } finally {
        writer.close();
      }

      final KijiDataRequest dataRequest = KijiDataRequest.builder()
          .addColumns(
              ColumnsDef
                  .create()
                  .withMaxVersions(100)
                  .add(pets, cat)
                  .add(pets, dog)
                  .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

Examples of org.kiji.schema.KijiTable

              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);
View Full Code Here

Examples of org.kiji.schema.KijiTable

                .withFamily("family").withQualifier("column").withValue(1L, "string-value")
            .withRow("dummy")
                .withFamily("family").withQualifier("column").withValue(1L, "string-value")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString()));
      assertEquals(15, mToolOutputLines.length);
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
  }
View Full Code Here

Examples of org.kiji.schema.KijiTable

                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "jane.doe@gmail.com")
                    .withQualifier("name").withValue(timestamp, "Jane Doe")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(),
          table.getURI().toString() + "info:name"
      ));
      assertEquals(18, mToolOutputLines.length);

      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(),
              table.getURI().toString() + "info:name,info:email"
          ));
      assertEquals(30, mToolOutputLines.length);

        EntityIdFactory eif = EntityIdFactory.getFactory(layout);
        EntityId startEid = eif.getEntityId("christophe@usermail.example.com"); //second row
        EntityId limitEid = eif.getEntityId("john.doe@gmail.com"); //second to last row
        String startHbaseRowKey = Hex.encodeHexString(startEid.getHBaseRowKey());
        String limitHbaseRowKey = Hex.encodeHexString(limitEid.getHBaseRowKey());
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(),
          table.getURI().toString() + "info:name",
          "--start-row=hbase=hex:" + startHbaseRowKey,  // start at the second row.
          "--limit-row=hbase=hex:" + limitHbaseRowKey   // end at the 2nd to last row (exclusive).
      ));
      assertEquals(9, mToolOutputLines.length);
View Full Code Here

Examples of org.kiji.schema.KijiTable

            .withRow("DC", "Technology", "stuff", 124, 1)
                .withFamily("family").withQualifier("column")
                    .withValue("Lydia")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString(),
          "--start-row=['NYC','Technology','widget',1,2]",
          "--limit-row=['NYC','Technology','widget',1,30]",
          "--debug"
          ));
      assertEquals(10, mToolOutputLines.length);
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString(),
          "--start-row=['NYC','Technology','widget']",
          "--limit-row=['NYC','Technology','widget',1,20]",
          "--debug"
          ));
    } finally {
View Full Code Here

Examples of org.kiji.schema.KijiTable

  @Test
  public void testTableNoFamilies() throws Exception {
    final Kiji kiji = new InstanceBuilder(getKiji())
        .withTable(KijiTableLayouts.getLayout(KijiTableLayouts.NOFAMILY))
        .build();
    final KijiTable table = kiji.openTable("nofamily");
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new ScanTool(), table.getURI().toString()));
    } finally {
      table.release();
    }
  }
View Full Code Here

Examples of org.kiji.schema.KijiTable

  /** 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);

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

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

Examples of org.kiji.schema.KijiTable

    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(),
            ilse.getMessage().contains("In column: 'info:gender'"));
        Assert.assertTrue(
            ilse.getMessage(),
            ilse.getMessage().contains("is incompatible with writer schema"));
      }

    } finally {
      table.release();
    }
  }
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.