description
stringlengths
11
2.86k
focal_method
stringlengths
70
6.25k
test_case
stringlengths
96
15.3k
["('/**\\\\n * Return a builder for columns associated with this KijiDataRequestBuilder.\\\\n *\\\\n * <p>Creates an object that allows you to specify a set of related columns attached\\\\n * to the same KijiDataRequest that all share the same retrieval properties, like\\\\n * the number of max versions.</p>\\\\n *\\\\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\\\n * data request builder.\\\\n */', '')"]
b'/**\n * Return a builder for columns associated with this KijiDataRequestBuilder.\n *\n * <p>Creates an object that allows you to specify a set of related columns attached\n * to the same KijiDataRequest that all share the same retrieval properties, like\n * the number of max versions.</p>\n *\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n * data request builder.\n */'public ColumnsDef newColumnsDef() { checkNotBuilt(); final ColumnsDef c = new ColumnsDef(); mColumnsDefs.add(c); return c; }
@Test public void testNoNegativePageSize() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.newColumnsDef().withPageSize(-5).addFamily("info"); fail("An exception should have been thrown."); } catch (IllegalArgumentException iae) { assertEquals("Page size must be 0 (disabled) or positive, but got: null", iae.getMessage()); } }
["('/**\\\\n * Return a builder for columns associated with this KijiDataRequestBuilder.\\\\n *\\\\n * <p>Creates an object that allows you to specify a set of related columns attached\\\\n * to the same KijiDataRequest that all share the same retrieval properties, like\\\\n * the number of max versions.</p>\\\\n *\\\\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\\\n * data request builder.\\\\n */', '')"]
b'/**\n * Return a builder for columns associated with this KijiDataRequestBuilder.\n *\n * <p>Creates an object that allows you to specify a set of related columns attached\n * to the same KijiDataRequest that all share the same retrieval properties, like\n * the number of max versions.</p>\n *\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n * data request builder.\n */'public ColumnsDef newColumnsDef() { checkNotBuilt(); final ColumnsDef c = new ColumnsDef(); mColumnsDefs.add(c); return c; }
@Test public void testNoZeroMaxVersions() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.newColumnsDef().withMaxVersions(0).addFamily("info"); fail("An exception should have been thrown."); } catch (IllegalArgumentException iae) { assertEquals("Maximum number of versions must be strictly positive, but got: 0", iae.getMessage()); } }
["('/**\\\\n * Construct a new KijiDataRequest based on the configuration specified in this builder\\\\n * and its associated column builders.\\\\n *\\\\n * <p>After calling build(), you may not use the builder anymore.</p>\\\\n *\\\\n * @return a new KijiDataRequest object containing the column requests associated\\\\n * with this KijiDataRequestBuilder.\\\\n */', '')", "('', '// Entire families for which a definition has been recorded:\\n')", "('', '// Fully-qualified columns for which a definition has been recorded:\\n')", "('', '// Families of fully-qualified columns for which definitions have been recorded:\\n')", "('', '// Iterate over the ColumnsDefs in the order they were added (mColumnsDef is a LinkedHashSet).\\n')"]
b'/**\n * Construct a new KijiDataRequest based on the configuration specified in this builder\n * and its associated column builders.\n *\n * <p>After calling build(), you may not use the builder anymore.</p>\n *\n * @return a new KijiDataRequest object containing the column requests associated\n * with this KijiDataRequestBuilder.\n */'public KijiDataRequest build() { checkNotBuilt(); mIsBuilt = true; // Entire families for which a definition has been recorded: final Set<String> families = Sets.newHashSet(); // Fully-qualified columns for which a definition has been recorded: final Set<KijiColumnName> columns = Sets.newHashSet(); // Families of fully-qualified columns for which definitions have been recorded: final Set<String> familiesOfColumns = Sets.newHashSet(); final List<KijiDataRequest.Column> requestedColumns = Lists.newArrayList(); // Iterate over the ColumnsDefs in the order they were added (mColumnsDef is a LinkedHashSet). for (ColumnsDef columnsDef : mColumnsDefs) { for (KijiDataRequest.Column column : columnsDef.buildColumns()) { if (column.getQualifier() == null) { final boolean isNotDuplicate = families.add(column.getFamily()); Preconditions.checkState(isNotDuplicate, "Duplicate definition for family '%s'.", column.getFamily()); Preconditions.checkState(!familiesOfColumns.contains(column.getFamily()), "KijiDataRequest may not simultaneously contain definitions for family '%s' " + "and definitions for fully qualified columns in family '%s'.", column.getFamily(), column.getFamily()); } else { final boolean isNotDuplicate = columns.add(column.getColumnName()); Preconditions.checkState(isNotDuplicate, "Duplicate definition for column '%s'.", column); Preconditions.checkState(!families.contains(column.getFamily()), "KijiDataRequest may not simultaneously contain definitions for family '%s' " + "and definitions for fully qualified columns '%s'.", column.getFamily(), column.getColumnName()); familiesOfColumns.add(column.getFamily()); } requestedColumns.add(column); } } return new KijiDataRequest(requestedColumns, mMinTimestamp, mMaxTimestamp); }
@Test public void testEmptyOk() { assertNotNull(KijiDataRequest.builder().build()); }
["('/**\\\\n * Return a builder for columns associated with this KijiDataRequestBuilder.\\\\n *\\\\n * <p>Creates an object that allows you to specify a set of related columns attached\\\\n * to the same KijiDataRequest that all share the same retrieval properties, like\\\\n * the number of max versions.</p>\\\\n *\\\\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\\\n * data request builder.\\\\n */', '')"]
b'/**\n * Return a builder for columns associated with this KijiDataRequestBuilder.\n *\n * <p>Creates an object that allows you to specify a set of related columns attached\n * to the same KijiDataRequest that all share the same retrieval properties, like\n * the number of max versions.</p>\n *\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n * data request builder.\n */'public ColumnsDef newColumnsDef() { checkNotBuilt(); final ColumnsDef c = new ColumnsDef(); mColumnsDefs.add(c); return c; }
@Test public void testNoSettingMaxVerTwice() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.newColumnsDef().withMaxVersions(2).withMaxVersions(3).addFamily("info"); fail("An exception should have been thrown."); } catch (IllegalStateException ise) { assertEquals("Cannot set max versions to 3, max versions already set to 2.", ise.getMessage()); } }
["('/**\\\\n * Return a builder for columns associated with this KijiDataRequestBuilder.\\\\n *\\\\n * <p>Creates an object that allows you to specify a set of related columns attached\\\\n * to the same KijiDataRequest that all share the same retrieval properties, like\\\\n * the number of max versions.</p>\\\\n *\\\\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\\\n * data request builder.\\\\n */', '')"]
b'/**\n * Return a builder for columns associated with this KijiDataRequestBuilder.\n *\n * <p>Creates an object that allows you to specify a set of related columns attached\n * to the same KijiDataRequest that all share the same retrieval properties, like\n * the number of max versions.</p>\n *\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n * data request builder.\n */'public ColumnsDef newColumnsDef() { checkNotBuilt(); final ColumnsDef c = new ColumnsDef(); mColumnsDefs.add(c); return c; }
@Test public void testNoSettingPageSizeTwice() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.newColumnsDef().withPageSize(2).withPageSize(3).addFamily("info"); fail("An exception should have been thrown."); } catch (IllegalStateException ise) { assertEquals("Cannot set page size to 3, page size already set to 2.", ise.getMessage()); } }
["('/**\\\\n * Sets the time range of cells to return: [<code>minTimestamp</code>,\\\\n * <code>maxTimestamp</code>).\\\\n *\\\\n * @param minTimestamp Request cells with a timestamp at least minTimestamp.\\\\n * @param maxTimestamp Request cells with a timestamp less than maxTimestamp.\\\\n * @return This data request builder instance.\\\\n */', '')"]
b'/**\n * Sets the time range of cells to return: [<code>minTimestamp</code>,\n * <code>maxTimestamp</code>).\n *\n * @param minTimestamp Request cells with a timestamp at least minTimestamp.\n * @param maxTimestamp Request cells with a timestamp less than maxTimestamp.\n * @return This data request builder instance.\n */'public KijiDataRequestBuilder withTimeRange(long minTimestamp, long maxTimestamp) { checkNotBuilt(); Preconditions.checkArgument(minTimestamp >= 0, "minTimestamp must be positive or zero, but got: %d", minTimestamp); Preconditions.checkArgument(maxTimestamp > minTimestamp, "Invalid time range [%d--%d]", minTimestamp, maxTimestamp); Preconditions.checkState(!mIsTimeRangeSet, "Cannot set time range more than once."); mIsTimeRangeSet = true; mMinTimestamp = minTimestamp; mMaxTimestamp = maxTimestamp; return this; }
@Test public void testNoSettingTimeRangeTwice() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.withTimeRange(2, 3).withTimeRange(6, 9); fail("An exception should have been thrown."); } catch (IllegalStateException ise) { assertEquals("Cannot set time range more than once.", ise.getMessage()); } }
["('/**\\\\n * Return a builder for columns associated with this KijiDataRequestBuilder.\\\\n *\\\\n * <p>Creates an object that allows you to specify a set of related columns attached\\\\n * to the same KijiDataRequest that all share the same retrieval properties, like\\\\n * the number of max versions.</p>\\\\n *\\\\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\\\n * data request builder.\\\\n */', '')"]
b'/**\n * Return a builder for columns associated with this KijiDataRequestBuilder.\n *\n * <p>Creates an object that allows you to specify a set of related columns attached\n * to the same KijiDataRequest that all share the same retrieval properties, like\n * the number of max versions.</p>\n *\n * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n * data request builder.\n */'public ColumnsDef newColumnsDef() { checkNotBuilt(); final ColumnsDef c = new ColumnsDef(); mColumnsDefs.add(c); return c; }
@Test public void testNoPropertiesAfterAdd() { KijiDataRequestBuilder builder = KijiDataRequest.builder(); try { builder.newColumnsDef().add("info", "foo").withMaxVersions(5); fail("An exception should have been thrown."); } catch (IllegalStateException ise) { assertEquals( "Properties of the columns builder cannot be changed once columns are assigned to it.", ise.getMessage()); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testSingleHostDefaultPort() { final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost/instance/table/col").build(); assertEquals("kiji-hbase", uri.getScheme()); assertEquals(1, uri.getZookeeperQuorum().size()); assertEquals("zkhost", uri.getZookeeperQuorum().get(0)); assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort()); assertEquals("instance", uri.getInstance()); assertEquals("table", uri.getTable()); assertEquals("col", uri.getColumns().get(0).getName()); }
Validates a data request against this validators table layout @param dataRequest The KijiDataRequest to validate @throws KijiDataRequestException If the data request is invalid
b"/**\n * Validates a data request against this validator's table layout.\n *\n * @param dataRequest The KijiDataRequest to validate.\n * @throws KijiDataRequestException If the data request is invalid.\n */"public void validate(KijiDataRequest dataRequest) { for (KijiDataRequest.Column column : dataRequest.getColumns()) { final String qualifier = column.getQualifier(); final KijiTableLayout.LocalityGroupLayout.FamilyLayout fLayout = mTableLayout.getFamilyMap().get(column.getFamily()); if (null == fLayout) { throw new KijiDataRequestException(String.format("Table '%s' has no family named '%s'.", mTableLayout.getName(), column.getFamily())); } if (fLayout.isGroupType() && (null != column.getQualifier())) { if (!fLayout.getColumnMap().containsKey(qualifier)) { throw new KijiDataRequestException(String.format("Table '%s' has no column '%s'.", mTableLayout.getName(), column.getName())); } } } }
@Test public void testValidate() throws InvalidLayoutException { KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3); builder.newColumnsDef().withMaxVersions(1).add("info", "name"); KijiDataRequest request = builder.build(); mValidator.validate(request); }
['("/**\\\\n * Validates a data request against this validator\'s table layout.\\\\n *\\\\n * @param dataRequest The KijiDataRequest to validate.\\\\n * @throws KijiDataRequestException If the data request is invalid.\\\\n */", \'\')']
b"/**\n * Validates a data request against this validator's table layout.\n *\n * @param dataRequest The KijiDataRequest to validate.\n * @throws KijiDataRequestException If the data request is invalid.\n */"public void validate(KijiDataRequest dataRequest) { for (KijiDataRequest.Column column : dataRequest.getColumns()) { final String qualifier = column.getQualifier(); final KijiTableLayout.LocalityGroupLayout.FamilyLayout fLayout = mTableLayout.getFamilyMap().get(column.getFamily()); if (null == fLayout) { throw new KijiDataRequestException(String.format("Table '%s' has no family named '%s'.", mTableLayout.getName(), column.getFamily())); } if (fLayout.isGroupType() && (null != column.getQualifier())) { if (!fLayout.getColumnMap().containsKey(qualifier)) { throw new KijiDataRequestException(String.format("Table '%s' has no column '%s'.", mTableLayout.getName(), column.getName())); } } } }
@Test public void testValidateNoSuchFamily() throws InvalidLayoutException { KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3); builder.newColumnsDef().withMaxVersions(1).add("blahblah", "name"); KijiDataRequest request = builder.build(); try { mValidator.validate(request); } catch (KijiDataRequestException kdre) { assertEquals("Table 'user' has no family named 'blahblah'.", kdre.getMessage()); } }
['("/**\\\\n * Validates a data request against this validator\'s table layout.\\\\n *\\\\n * @param dataRequest The KijiDataRequest to validate.\\\\n * @throws KijiDataRequestException If the data request is invalid.\\\\n */", \'\')']
b"/**\n * Validates a data request against this validator's table layout.\n *\n * @param dataRequest The KijiDataRequest to validate.\n * @throws KijiDataRequestException If the data request is invalid.\n */"public void validate(KijiDataRequest dataRequest) { for (KijiDataRequest.Column column : dataRequest.getColumns()) { final String qualifier = column.getQualifier(); final KijiTableLayout.LocalityGroupLayout.FamilyLayout fLayout = mTableLayout.getFamilyMap().get(column.getFamily()); if (null == fLayout) { throw new KijiDataRequestException(String.format("Table '%s' has no family named '%s'.", mTableLayout.getName(), column.getFamily())); } if (fLayout.isGroupType() && (null != column.getQualifier())) { if (!fLayout.getColumnMap().containsKey(qualifier)) { throw new KijiDataRequestException(String.format("Table '%s' has no column '%s'.", mTableLayout.getName(), column.getName())); } } } }
@Test public void testValidateNoSuchColumn() throws InvalidLayoutException { KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3); builder.newColumnsDef().withMaxVersions(1) .add("info", "name") .add("info", "blahblah"); KijiDataRequest request = builder.build(); try { mValidator.validate(request); } catch (KijiDataRequestException kdre) { assertEquals("Table 'user' has no column 'info:blahblah'.", kdre.getMessage()); } }
@inheritDoc
b'/** {@inheritDoc} */'@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().equals(obj.getClass())) { return false; } final KijiRowKeyComponents krkc = (KijiRowKeyComponents)obj; return Arrays.deepEquals(mComponents, krkc.mComponents); }
@Test public void testEquals() throws Exception { KijiRowKeyComponents krkc1 = KijiRowKeyComponents.fromComponents( "jennyanydots", 1, null, null); KijiRowKeyComponents krkc2 = KijiRowKeyComponents.fromComponents( "jennyanydots", 1, null, null); KijiRowKeyComponents krkc3 = KijiRowKeyComponents.fromComponents( "jennyanydots", 1, null); assertFalse(krkc1 == krkc2); assertEquals(krkc1, krkc2); assertFalse(krkc1.equals(krkc3)); // byte[] use a different code path. byte[] bytes1 = new byte[]{47}; byte[] bytes2 = new byte[]{47}; assertFalse(bytes1.equals(bytes2)); KijiRowKeyComponents krkc4 = KijiRowKeyComponents.fromComponents(bytes1); KijiRowKeyComponents krkc5 = KijiRowKeyComponents.fromComponents(bytes2); assertEquals(krkc4, krkc5); }
@inheritDoc
b'/** {@inheritDoc} */'@Override public int hashCode() { return Arrays.deepHashCode(mComponents); }
@Test public void testHashCode() throws Exception { byte[] bytes1 = new byte[]{47}; byte[] bytes2 = new byte[]{47}; assertFalse(bytes1.equals(bytes2)); KijiRowKeyComponents krkc1 = KijiRowKeyComponents.fromComponents(bytes1); KijiRowKeyComponents krkc2 = KijiRowKeyComponents.fromComponents(bytes2); assertEquals(krkc1.hashCode(), krkc2.hashCode()); }
["('/**\\\\n * Creates a KijiRowKeyComponents from components.\\\\n *\\\\n * @param components the components of the row key.\\\\n * @return a KijiRowKeyComponents\\\\n */', '')", "('', '// Some of these checks will be redundant when the KijiRowKeyComponents is converted\\n')", "('', '// into an EntityId, but putting them here helps the user see them at the time of creation.\\n')", "('', '// We need to make a deep copy of the byte[] to ensure that a later mutation to the original\\n')", '(\'\', "// byte[] doesn\'t confuse hash codes, etc.\\n")', "('', '// Pass in a copy rather than the actual array, just in case the user called us with an\\n')", "('', '// Object[], which would make components mutable.\\n')"]
b'/**\n * Creates a KijiRowKeyComponents from components.\n *\n * @param components the components of the row key.\n * @return a KijiRowKeyComponents\n */'public static KijiRowKeyComponents fromComponents(Object... components) { Preconditions.checkNotNull(components); Preconditions.checkArgument(components.length > 0); Preconditions.checkNotNull(components[0], "First component cannot be null."); // Some of these checks will be redundant when the KijiRowKeyComponents is converted // into an EntityId, but putting them here helps the user see them at the time of creation. if (components[0] instanceof byte[]) { Preconditions.checkArgument(components.length == 1, "byte[] only valid as sole component."); // We need to make a deep copy of the byte[] to ensure that a later mutation to the original // byte[] doesn't confuse hash codes, etc. byte[] original = (byte[])components[0]; return new KijiRowKeyComponents(new Object[]{Arrays.copyOf(original, original.length)}); } else { boolean seenNull = false; for (int i = 0; i < components.length; i++) { if (seenNull) { Preconditions.checkArgument( components[i] == null, "Kiji Row Keys cannot contain have a non-null component after a null component"); } else { Object part = components[i]; if (part == null) { seenNull = true; } else { Preconditions.checkArgument( (part instanceof String) || (part instanceof Integer) || (part instanceof Long), "Components must be of type String, Integer, or Long."); } } } } // Pass in a copy rather than the actual array, just in case the user called us with an // Object[], which would make components mutable. return new KijiRowKeyComponents(Arrays.copyOf(components, components.length)); }
@Test public void testFormattedCompare() { List<KijiRowKeyComponents> sorted = ImmutableList.of( KijiRowKeyComponents.fromComponents("a", null, null), KijiRowKeyComponents.fromComponents("a", 123, 456L), KijiRowKeyComponents.fromComponents("a", 456, null)); List<KijiRowKeyComponents> shuffled = Lists.newArrayList(sorted); Collections.shuffle(shuffled); Collections.sort(shuffled); Assert.assertEquals(sorted, shuffled); }
["('/**\\\\n * Creates a KijiRowKeyComponents from components.\\\\n *\\\\n * @param components the components of the row key.\\\\n * @return a KijiRowKeyComponents\\\\n */', '')", "('', '// Some of these checks will be redundant when the KijiRowKeyComponents is converted\\n')", "('', '// into an EntityId, but putting them here helps the user see them at the time of creation.\\n')", "('', '// We need to make a deep copy of the byte[] to ensure that a later mutation to the original\\n')", '(\'\', "// byte[] doesn\'t confuse hash codes, etc.\\n")', "('', '// Pass in a copy rather than the actual array, just in case the user called us with an\\n')", "('', '// Object[], which would make components mutable.\\n')"]
b'/**\n * Creates a KijiRowKeyComponents from components.\n *\n * @param components the components of the row key.\n * @return a KijiRowKeyComponents\n */'public static KijiRowKeyComponents fromComponents(Object... components) { Preconditions.checkNotNull(components); Preconditions.checkArgument(components.length > 0); Preconditions.checkNotNull(components[0], "First component cannot be null."); // Some of these checks will be redundant when the KijiRowKeyComponents is converted // into an EntityId, but putting them here helps the user see them at the time of creation. if (components[0] instanceof byte[]) { Preconditions.checkArgument(components.length == 1, "byte[] only valid as sole component."); // We need to make a deep copy of the byte[] to ensure that a later mutation to the original // byte[] doesn't confuse hash codes, etc. byte[] original = (byte[])components[0]; return new KijiRowKeyComponents(new Object[]{Arrays.copyOf(original, original.length)}); } else { boolean seenNull = false; for (int i = 0; i < components.length; i++) { if (seenNull) { Preconditions.checkArgument( components[i] == null, "Kiji Row Keys cannot contain have a non-null component after a null component"); } else { Object part = components[i]; if (part == null) { seenNull = true; } else { Preconditions.checkArgument( (part instanceof String) || (part instanceof Integer) || (part instanceof Long), "Components must be of type String, Integer, or Long."); } } } } // Pass in a copy rather than the actual array, just in case the user called us with an // Object[], which would make components mutable. return new KijiRowKeyComponents(Arrays.copyOf(components, components.length)); }
@Test public void testRawCompare() { final List<KijiRowKeyComponents> sorted = ImmutableList.of( KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x00, 0x00}}), KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x00, 0x01}}), KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x01, 0x00}})); List<KijiRowKeyComponents> shuffled = Lists.newArrayList(sorted); Collections.shuffle(shuffled); Collections.sort(shuffled); Assert.assertEquals(sorted, shuffled); }
Resolution in number of bytes when generating evenly spaced HBase row keys @return the number of bytes required by an md5 hash
b'/**\n * Resolution (in number of bytes) when generating evenly spaced HBase row keys.\n *\n * @return the number of bytes required by an md5 hash.\n */'@Deprecated public int getRowKeyResolution() { return 16; }
@Test public void testGetRowKeyResolution() throws IOException { assertEquals(2, KijiRowKeySplitter .getRowKeyResolution(KijiTableLayouts.getLayout(KijiTableLayouts.FORMATTED_RKF))); assertEquals(16, KijiRowKeySplitter .getRowKeyResolution(KijiTableLayouts.getLayout(KijiTableLayouts.FULL_FEATURED))); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testIllegalScheme() { try { KijiURI.newBuilder("kiji-foo:///"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertTrue(kurie.getMessage().contains("No parser available for")); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testNoAuthority() { try { KijiURI.newBuilder("kiji:///"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji:///' : ZooKeeper ensemble missing.", kurie.getMessage()); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHosts() { final KijiURI uri = KijiURI.newBuilder("kiji-hbase://(zkhost1,zkhost2):1234/instance/table/col").build(); assertEquals("kiji-hbase", uri.getScheme()); assertEquals("zkhost1", uri.getZookeeperQuorum().get(0)); assertEquals("zkhost2", uri.getZookeeperQuorum().get(1)); assertEquals(1234, uri.getZookeeperClientPort()); assertEquals("instance", uri.getInstance()); assertEquals("table", uri.getTable()); assertEquals("col", uri.getColumns().get(0).getName()); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsNoParen() { try { KijiURI.newBuilder("kiji://zkhost1,zkhost2:1234/instance/table/col"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji://zkhost1,zkhost2:1234/instance/table/col' : Multiple " + "ZooKeeper hosts must be parenthesized.", kurie.getMessage()); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsMultiplePorts() { try { KijiURI.newBuilder("kiji://zkhost1:1234,zkhost2:2345/instance/table/col"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji://zkhost1:1234,zkhost2:2345/instance/table/col' : " + "Invalid ZooKeeper ensemble cluster identifier.", kurie.getMessage()); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testExtraPath() { try { KijiURI.newBuilder("kiji://(zkhost1,zkhost2):1234/instance/table/col/extra"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji://(zkhost1,zkhost2):1234/instance/table/col/extra' : " + "Too many path segments.", kurie.getMessage()); } }
@inheritDoc
b'/** {@inheritDoc} */'@Override public String toString() { return toString(false); }
@Test public void testToString() { String uri = "kiji://(zkhost1,zkhost2):1234/instance/table/col/"; assertEquals(uri, KijiURI.newBuilder(uri).build().toString()); uri = "kiji://zkhost1:1234/instance/table/col/"; assertEquals(uri, KijiURI.newBuilder(uri).build().toString()); uri = "kiji://zkhost:1234/instance/table/col1,col2/"; assertEquals(uri, KijiURI.newBuilder(uri).build().toString()); uri = "kiji://zkhost:1234/.unset/table/col/"; assertEquals(uri, KijiURI.newBuilder(uri).build().toString()); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with defaults for an HBase cluster.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with defaults for an HBase cluster.\n */'public static KijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testKijiURIBuilderFromInstance() { final KijiURI uri = KijiURI.newBuilder("kiji://zkhost:1234/.unset/table").build(); KijiURI built = KijiURI.newBuilder(uri).build(); assertEquals(uri, built); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public void close() throws IOException { mQualifierPager.close(); }
@Test public void testQualifiersIterator() throws IOException { final EntityId eid = mTable.getEntityId("me"); final KijiDataRequest dataRequest = KijiDataRequest.builder() .addColumns(ColumnsDef.create() .withMaxVersions(HConstants.ALL_VERSIONS).withPageSize(1).addFamily("jobs")) .build(); final KijiRowData row = mReader.get(eid, dataRequest); final MapFamilyQualifierIterator it = new MapFamilyQualifierIterator(row, "jobs", 3); try { final List<String> qualifiers = Lists.newArrayList((Iterator<String>) it); Assert.assertEquals(Lists.newArrayList("j0", "j1", "j2", "j3", "j4"), qualifiers); } finally { it.close(); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public void close() throws IOException { mQualifierIterator.close(); if (mVersionIterator != null) { mVersionIterator.close(); } }
@Test public void testQualifiersIterator() throws IOException { final EntityId eid = mTable.getEntityId("me"); final KijiDataRequest dataRequest = KijiDataRequest.builder() .addColumns(ColumnsDef.create() .withMaxVersions(HConstants.ALL_VERSIONS).withPageSize(1).addFamily("jobs")) .build(); final KijiRowData row = mReader.get(eid, dataRequest); final MapFamilyVersionIterator<Utf8> it = new MapFamilyVersionIterator<Utf8>(row, "jobs", 3, 2); try { int ncells = 0; int ijob = 0; int timestamp = 5; for (Entry<Utf8> entry : it) { assertEquals(String.format("j%d", ijob), entry.getQualifier()); assertEquals(timestamp, entry.getTimestamp()); assertEquals(String.format("j%d-t%d", ijob, timestamp), entry.getValue().toString()); timestamp -= 1; if (timestamp == 0) { timestamp = 5; ijob += 1; } ncells += 1; } assertEquals(NJOBS * NTIMESTAMPS, ncells); } finally { it.close(); } }
Creates a raw entity ID @param rowKey KijiHBase row key both row keys are identical
b'/**\n * Creates a raw entity ID.\n *\n * @param rowKey Kiji/HBase row key (both row keys are identical).\n */'private RawEntityId(byte[] rowKey) { mBytes = Preconditions.checkNotNull(rowKey); }
@Test public void testRawEntityId() { final byte[] bytes = new byte[] {0x11, 0x22}; final RawEntityId eid = RawEntityId.getEntityId(bytes); assertArrayEquals(bytes, (byte[])eid.getComponentByIndex(0)); assertArrayEquals(bytes, eid.getHBaseRowKey()); assertEquals(1, eid.getComponents().size()); assertEquals(bytes, eid.getComponents().get(0)); }
Loads the dictionary from a file @param filename The path to a file of words one per line @return The list of words from the file @throws IOException If there is an error reading the words from the file
b'/**\n * Loads the dictionary from a file.\n *\n * @param filename The path to a file of words, one per line.\n * @return The list of words from the file.\n * @throws IOException If there is an error reading the words from the file.\n */'public List<String> load(String filename) throws IOException { FileInputStream fileStream = new FileInputStream(filename); try { return load(fileStream); } finally { fileStream.close(); } }
@Test public void testLoad() throws IOException { DictionaryLoader loader = new DictionaryLoader(); List<String> dictionary = loader.load(getClass().getClassLoader().getResourceAsStream( "org/kiji/schema/tools/synth/dictionary.txt")); assertEquals(3, dictionary.size()); assertEquals("apple", dictionary.get(0)); assertEquals("banana", dictionary.get(1)); assertEquals("carrot", dictionary.get(2)); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsDefaultPort() { final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2/instance/table/col").build(); assertEquals("kiji-hbase", uri.getScheme()); assertEquals("zkhost1", uri.getZookeeperQuorum().get(0)); assertEquals("zkhost2", uri.getZookeeperQuorum().get(1)); assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort()); assertEquals("instance", uri.getInstance()); assertEquals("table", uri.getTable()); assertEquals("col", uri.getColumns().get(0).getName()); }
Construct an email address string @param username The part before the @ symbol @param domain The part after the @ symbol @return An email address ltusernamegt@ltdomaingt
b"/**\n * Construct an email address string.\n *\n * @param username The part before the '@' symbol.\n * @param domain The part after the '@' symbol.\n * @return An email address (&lt;username&gt;@&lt;domain&gt;).\n */"public static String formatEmail(String username, String domain) { return username + "@" + domain; }
@Test public void testFormatEmail() { assertEquals("a@b.com", EmailSynthesizer.formatEmail("a", "b.com")); }
["('', '// Pick n words from the dictionary.\\n')"]
@Override public String synthesize() { // Pick n words from the dictionary. List<String> grams = new ArrayList<String>(mN); for (int i = 0; i < mN; i++) { grams.add(mWordSynthesizer.synthesize()); } return StringUtils.join(grams, " "); }
@Test public void testWordSynth() { WordSynthesizer wordSynthesizer = createStrictMock(WordSynthesizer.class); expect(wordSynthesizer.synthesize()).andReturn("a"); expect(wordSynthesizer.synthesize()).andReturn("b"); expect(wordSynthesizer.synthesize()).andReturn("c"); expect(wordSynthesizer.synthesize()).andReturn("d"); replay(wordSynthesizer); NGramSynthesizer synth = new NGramSynthesizer(wordSynthesizer, 2); assertEquals("a b", synth.synthesize()); assertEquals("c d", synth.synthesize()); verify(wordSynthesizer); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "create-table"; }
@Test public void testCreateHashedTableWithNumRegions() throws Exception { final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST); final File layoutFile = getTempLayoutFile(layout); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); assertEquals(BaseTool.SUCCESS, runTool(new CreateTableTool(), "--table=" + tableURI, "--layout=" + layoutFile, "--num-regions=" + 2, "--debug" )); assertEquals(2, mToolOutputLines.length); assertTrue(mToolOutputLines[0].startsWith("Parsing table layout: ")); assertTrue(mToolOutputLines[1].startsWith("Creating Kiji table")); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "create-table"; }
@Test public void testCreateUnhashedTableWithSplitKeys() throws Exception { final KijiTableLayout layout = KijiTableLayout.newLayout(KijiTableLayouts.getFooUnhashedTestLayout()); final File layoutFile = getTempLayoutFile(layout); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); final String splitKeyFile = getClass().getClassLoader().getResource(REGION_SPLIT_KEY_FILE).getPath(); assertEquals(BaseTool.SUCCESS, runTool(new CreateTableTool(), "--table=" + tableURI, "--layout=" + layoutFile, "--split-key-file=file://" + splitKeyFile, "--debug" )); assertEquals(2, mToolOutputLines.length); assertTrue(mToolOutputLines[0].startsWith("Parsing table layout: ")); assertTrue(mToolOutputLines[1].startsWith("Creating Kiji table")); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "create-table"; }
@Test public void testCreateHashedTableWithSplitKeys() throws Exception { final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST_LEGACY); final File layoutFile = getTempLayoutFile(layout); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); final String splitKeyFile = getClass().getClassLoader().getResource(REGION_SPLIT_KEY_FILE).getPath(); try { runTool(new CreateTableTool(), "--table=" + tableURI, "--layout=" + layoutFile, "--split-key-file=file://" + splitKeyFile ); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { assertTrue(iae.getMessage().startsWith( "Row key hashing is enabled for the table. Use --num-regions=N instead.")); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "create-table"; }
@Test public void testCreateUnhashedTableWithNumRegions() throws Exception { final KijiTableLayout layout = KijiTableLayout.newLayout(KijiTableLayouts.getFooUnhashedTestLayout()); final File layoutFile = getTempLayoutFile(layout); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); try { runTool(new CreateTableTool(), "--table=" + tableURI, "--layout=" + layoutFile, "--num-regions=4" ); fail("Should throw InvalidLayoutException"); } catch (IllegalArgumentException iae) { assertTrue(iae.getMessage().startsWith( "May not use numRegions > 1 if row key hashing is disabled in the layout")); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "create-table"; }
@Test public void testCreateTableWithInvalidSchemaClassInLayout() throws Exception { final TableLayoutDesc layout = KijiTableLayouts.getLayout(KijiTableLayouts.INVALID_SCHEMA); final File layoutFile = getTempLayoutFile(layout); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); try { runTool(new CreateTableTool(), "--table=" + tableURI, "--layout=" + layoutFile ); fail("Should throw InvalidLayoutException"); } catch (InvalidLayoutException ile) { assertTrue(ile.getMessage(), ile.getMessage().startsWith( "Invalid cell specification with Avro class type has invalid class name: '\"string\"'.")); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "get"; }
@Test public void testGetFromTable() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE); kiji.createTable(layout.getName(), layout); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("hashed") .withFamily("family").withQualifier("column").withValue(314L, "value") .build(); final KijiTable table = kiji.openTable(layout.getName()); try { assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(), "--entity-id=hashed")); } finally { ResourceUtils.releaseOrLog(table); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "get"; }
@Test public void testGetFromTableMore() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST); final long timestamp = 10L; new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("gwu@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "gwu@usermail.example.com") .withQualifier("name").withValue(timestamp, "Garrett Wu") .withRow("aaron@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "aaron@usermail.example.com") .withQualifier("name").withValue(timestamp, "Aaron Kimball") .withRow("christophe@usermail.example.com") .withFamily("info") .withQualifier("email") .withValue(timestamp, "christophe@usermail.example.com") .withQualifier("name").withValue(timestamp, "Christophe Bisciglia") .withRow("kiyan@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "kiyan@usermail.example.com") .withQualifier("name").withValue(timestamp, "Kiyan Ahmadizadeh") .withRow("john.doe@gmail.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "john.doe@gmail.com") .withQualifier("name").withValue(timestamp, "John Doe") .withRow("jane.doe@gmail.com") .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 GetTool(), table.getURI().toString(), "--entity-id=[\"jane.doe@gmail.com\"]")); assertEquals(5, mToolOutputLines.length); EntityId eid = EntityIdFactory.getFactory(layout).getEntityId("gwu@usermail.example.com"); String hbaseRowKey = Hex.encodeHexString(eid.getHBaseRowKey()); assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI() + "info:name", "--entity-id=hbase=hex:" + hbaseRowKey )); assertEquals(3, mToolOutputLines.length); // TODO: Validate GetTool output } finally { ResourceUtils.releaseOrLog(table); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsDefaultPortDefaultInstance() { final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2/default/table/col").build(); assertEquals("kiji-hbase", uri.getScheme()); assertEquals("zkhost1", uri.getZookeeperQuorum().get(0)); assertEquals("zkhost2", uri.getZookeeperQuorum().get(1)); assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort()); assertEquals("default", uri.getInstance()); assertEquals("table", uri.getTable()); assertEquals("col", uri.getColumns().get(0).getName()); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "get"; }
@Test public void testGetFormattedRKF() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("NYC", "Technology", "widget", 1, 2) .withFamily("family").withQualifier("column") .withValue("Candaules") .withRow("NYC", "Technology", "widget", 1, 20) .withFamily("family").withQualifier("column") .withValue("Croesus") .withRow("NYC", "Technology", "thingie", 2) .withFamily("family").withQualifier("column") .withValue("Gyges") .withRow("DC", "Technology", "stuff", 123) .withFamily("family").withQualifier("column") .withValue("Glaucon") .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 GetTool(), table.getURI().toString(), "--entity-id=['NYC','Technology','widget',1,2]" )); assertEquals(3, mToolOutputLines.length); assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(), "--entity-id=['NYC','Technology','thingie',2,null]" )); assertEquals(3, mToolOutputLines.length); } finally { ResourceUtils.releaseOrLog(table); } }
['("/**\\\\n * Return the tool specified by the \'toolName\' argument.\\\\n * (package-protected for use by the HelpTool, and for testing.)\\\\n *\\\\n * @param toolName the name of the tool to instantiate.\\\\n * @return the KijiTool that provides for that name, or null if none does.\\\\n */", \'\')', "('', '// Iterate over available tools, searching for the one with\\n')", "('', '// the same name as the supplied tool name argument.\\n')"]
b"/**\n * Return the tool specified by the 'toolName' argument.\n * (package-protected for use by the HelpTool, and for testing.)\n *\n * @param toolName the name of the tool to instantiate.\n * @return the KijiTool that provides for that name, or null if none does.\n */"KijiTool getToolForName(String toolName) { KijiTool tool = null; // Iterate over available tools, searching for the one with // the same name as the supplied tool name argument. for (KijiTool candidate : Lookups.get(KijiTool.class)) { if (toolName.equals(candidate.getName())) { tool = candidate; break; } } return tool; }
@Test public void testGetToolName() { KijiTool tool = new KijiToolLauncher().getToolForName("ls"); assertNotNull("Got a null tool back, should have gotten a real one.", tool); assertEquals("Tool does not advertise it responds to 'ls'.", "ls", tool.getName()); assertTrue("Didn't get the LsTool we expected!", tool instanceof LsTool); }
['("/**\\\\n * Return the tool specified by the \'toolName\' argument.\\\\n * (package-protected for use by the HelpTool, and for testing.)\\\\n *\\\\n * @param toolName the name of the tool to instantiate.\\\\n * @return the KijiTool that provides for that name, or null if none does.\\\\n */", \'\')', "('', '// Iterate over available tools, searching for the one with\\n')", "('', '// the same name as the supplied tool name argument.\\n')"]
b"/**\n * Return the tool specified by the 'toolName' argument.\n * (package-protected for use by the HelpTool, and for testing.)\n *\n * @param toolName the name of the tool to instantiate.\n * @return the KijiTool that provides for that name, or null if none does.\n */"KijiTool getToolForName(String toolName) { KijiTool tool = null; // Iterate over available tools, searching for the one with // the same name as the supplied tool name argument. for (KijiTool candidate : Lookups.get(KijiTool.class)) { if (toolName.equals(candidate.getName())) { tool = candidate; break; } } return tool; }
@Test public void testGetMissingTool() { KijiTool tool = new KijiToolLauncher().getToolForName("this-tool/can't1`exist"); assertNull(tool); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "layout"; }
@Test public void testChangeRowKeyHashing() throws Exception { final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST_LEGACY); getKiji().createTable(layout.getDesc()); final File newLayoutFile = getTempLayoutFile(KijiTableLayouts.getFooChangeHashingTestLayout()); final KijiURI tableURI = KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build(); try { runTool(new LayoutTool(), "--table=" + tableURI, "--do=set", "--layout=" + newLayoutFile ); fail("Should throw InvalidLayoutException"); } catch (InvalidLayoutException ile) { assertTrue(ile.getMessage().startsWith( "Invalid layout update from reference row keys format")); } }
Parses a table name for a kiji instance name @param kijiTableName The table name to parse @return instance name or null if none found
b'/**\n * Parses a table name for a kiji instance name.\n *\n * @param kijiTableName The table name to parse\n * @return instance name (or null if none found)\n */'protected static String parseInstanceName(String kijiTableName) { final String[] parts = StringUtils.split(kijiTableName, '\u0000', '.'); if (parts.length < 3 || !KijiURI.KIJI_SCHEME.equals(parts[0])) { return null; } return parts[1]; }
@Test public void testParseInstanceName() { assertEquals("default", LsTool.parseInstanceName("kiji.default.meta")); assertEquals("default", LsTool.parseInstanceName("kiji.default.schema_hash")); assertEquals("default", LsTool.parseInstanceName("kiji.default.schema_id")); assertEquals("default", LsTool.parseInstanceName("kiji.default.system")); assertEquals("default", LsTool.parseInstanceName("kiji.default.table.job_history")); }
["('/**\\\\n * Parses a table name for a kiji instance name.\\\\n *\\\\n * @param kijiTableName The table name to parse\\\\n * @return instance name (or null if none found)\\\\n */', '')"]
b'/**\n * Parses a table name for a kiji instance name.\n *\n * @param kijiTableName The table name to parse\n * @return instance name (or null if none found)\n */'protected static String parseInstanceName(String kijiTableName) { final String[] parts = StringUtils.split(kijiTableName, '\u0000', '.'); if (parts.length < 3 || !KijiURI.KIJI_SCHEME.equals(parts[0])) { return null; } return parts[1]; }
@Test public void testParseNonKijiTable() { String tableName = "hbase_table"; assertEquals(null, LsTool.parseInstanceName(tableName)); }
["('/**\\\\n * Parses a table name for a kiji instance name.\\\\n *\\\\n * @param kijiTableName The table name to parse\\\\n * @return instance name (or null if none found)\\\\n */', '')"]
b'/**\n * Parses a table name for a kiji instance name.\n *\n * @param kijiTableName The table name to parse\n * @return instance name (or null if none found)\n */'protected static String parseInstanceName(String kijiTableName) { final String[] parts = StringUtils.split(kijiTableName, '\u0000', '.'); if (parts.length < 3 || !KijiURI.KIJI_SCHEME.equals(parts[0])) { return null; } return parts[1]; }
@Test public void testParseMalformedKijiTableName() { assertEquals(null, LsTool.parseInstanceName("kiji.default")); assertEquals(null, LsTool.parseInstanceName("kiji.")); assertEquals(null, LsTool.parseInstanceName("kiji")); }
Lists all kiji instances @param hbaseURI URI of the HBase instance to list the content of @return A program exit code zero on success @throws IOException If there is an error
b'/**\n * Lists all kiji instances.\n *\n * @param hbaseURI URI of the HBase instance to list the content of.\n * @return A program exit code (zero on success).\n * @throws IOException If there is an error.\n */'private int listInstances(KijiURI hbaseURI) throws IOException { for (String instanceName : getInstanceNames(hbaseURI)) { getPrintStream().println(KijiURI.newBuilder(hbaseURI).withInstanceName(instanceName).build()); } return SUCCESS; }
@Test public void testListInstances() throws Exception { final Kiji kiji = getKiji(); final KijiURI hbaseURI = KijiURI.newBuilder(kiji.getURI()).withInstanceName(null).build(); final LsTool ls = new LsTool(); assertEquals(BaseTool.SUCCESS, runTool(ls, hbaseURI.toString())); final Set<String> instances = Sets.newHashSet(mToolOutputLines); assertTrue(instances.contains(kiji.getURI().toString())); }
Lists all the tables in a kiji instance @param kiji Kiji instance to list the tables of @return A program exit code zero on success @throws IOException If there is an error
b'/**\n * Lists all the tables in a kiji instance.\n *\n * @param kiji Kiji instance to list the tables of.\n * @return A program exit code (zero on success).\n * @throws IOException If there is an error.\n */'private int listTables(Kiji kiji) throws IOException { for (String name : kiji.getTableNames()) { getPrintStream().println(kiji.getURI() + name); } return SUCCESS; }
@Test public void testListTables() throws Exception { final Kiji kiji = getKiji(); assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString())); assertEquals(1, mToolOutputLines.length); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE); kiji.createTable(layout.getDesc()); assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString())); assertEquals(1, mToolOutputLines.length); assertEquals(kiji.getURI() + layout.getName(), mToolOutputLines[0]); }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "ls"; }
@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); } }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testIllegalScheme() { try { KijiURI.newBuilder("kiji-foo:///"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertTrue(kurie.getMessage().contains("No parser available for")); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "ls"; }
@Test public void testFormattedRowKey() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("dummy", "str1", "str2", 1, 2L) .withFamily("family").withQualifier("column") .withValue(1L, "string-value") .withValue(2L, "string-value2") .withRow("dummy", "str1", "str2", 1) .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1", "str2") .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1") .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 LsTool(), table.getURI().toString())); } finally { ResourceUtils.releaseOrLog(table); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "ls"; }
@Test public void testKijiLsStartAndLimitRow() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST); kiji.createTable(layout.getDesc()); final KijiTable table = kiji.openTable(layout.getName()); try { assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), table.getURI().toString())); // TODO: Validate output } finally { ResourceUtils.releaseOrLog(table); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "ls"; }
@Test public void testMultipleArguments() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("dummy", "str1", "str2", 1, 2L) .withFamily("family").withQualifier("column") .withValue(1L, "string-value") .withValue(2L, "string-value2") .withRow("dummy", "str1", "str2", 1) .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1", "str2") .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1") .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy") .withFamily("family").withQualifier("column").withValue(1L, "string-value") .build(); final KijiTableLayout layoutTwo = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST); kiji.createTable(layoutTwo.getDesc()); final KijiTable table = kiji.openTable(layout.getName()); try { final KijiTable tableTwo = kiji.openTable(layoutTwo.getName()); try { assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), table.getURI().toString(), tableTwo.getURI().toString())); assertEquals(9, mToolOutputLines.length); assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString())); assertEquals(2, mToolOutputLines.length); assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString(), table.getURI().toString())); assertEquals(3, mToolOutputLines.length); } finally { tableTwo.release(); } } finally { table.release(); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "scan"; }
@Test public void testFormattedRowKey() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("dummy", "str1", "str2", 1, 2L) .withFamily("family").withQualifier("column") .withValue(1L, "string-value") .withValue(2L, "string-value2") .withRow("dummy", "str1", "str2", 1) .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1", "str2") .withFamily("family").withQualifier("column").withValue(1L, "string-value") .withRow("dummy", "str1") .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); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "scan"; }
@Test public void testKijiScanStartAndLimitRow() throws Exception { final Kiji kiji = getKiji(); TableLayoutDesc desc = KijiTableLayouts.getLayout(KijiTableLayouts.FOO_TEST); ((RowKeyFormat2)desc.getKeysFormat()).setEncoding(RowKeyEncoding.RAW); final KijiTableLayout layout = KijiTableLayout.newLayout(desc); final long timestamp = 10L; new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("gwu@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "gwu@usermail.example.com") .withQualifier("name").withValue(timestamp, "Garrett Wu") .withRow("aaron@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "aaron@usermail.example.com") .withQualifier("name").withValue(timestamp, "Aaron Kimball") .withRow("christophe@usermail.example.com") .withFamily("info") .withQualifier("email") .withValue(timestamp, "christophe@usermail.example.com") .withQualifier("name").withValue(timestamp, "Christophe Bisciglia") .withRow("kiyan@usermail.example.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "kiyan@usermail.example.com") .withQualifier("name").withValue(timestamp, "Kiyan Ahmadizadeh") .withRow("john.doe@gmail.com") .withFamily("info") .withQualifier("email").withValue(timestamp, "john.doe@gmail.com") .withQualifier("name").withValue(timestamp, "John Doe") .withRow("jane.doe@gmail.com") .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); } finally { ResourceUtils.releaseOrLog(table); } }
["('/** {@inheritDoc} */', '')"]
b'/** {@inheritDoc} */'@Override public String getName() { return "scan"; }
@Test public void testRangeScanFormattedRKF() throws Exception { final Kiji kiji = getKiji(); final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF); new InstanceBuilder(kiji) .withTable(layout.getName(), layout) .withRow("NYC", "Technology", "widget", 1, 2) .withFamily("family").withQualifier("column") .withValue("Candaules") .withRow("NYC", "Technology", "widget", 1, 20) .withFamily("family").withQualifier("column") .withValue("Croesus") .withRow("NYC", "Technology", "thingie", 2) .withFamily("family").withQualifier("column") .withValue("Gyges") .withRow("DC", "Technology", "stuff", 123) .withFamily("family").withQualifier("column") .withValue("Glaucon") .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 { ResourceUtils.releaseOrLog(table); } }
Register a schema @return Tool exit code @throws IOException in case of an error
b'/**\n * Register a schema.\n *\n * @return Tool exit code.\n * @throws IOException in case of an error.\n */'private int registerSchema() throws IOException { final KijiSchemaTable table = mKiji.getSchemaTable(); final File file = new File(mRegisterFlag); final Schema schema = new Schema.Parser().parse(file); final long id = table.getOrCreateSchemaId(schema); final String hash = table.getSchemaHash(schema).toString(); if (isInteractive()) { getPrintStream().print("Schema ID for the given schema is: "); } getPrintStream().println(id); if (isInteractive()) { getPrintStream().print("Schema hash for the given schema is: "); } getPrintStream().println(hash); return SUCCESS; }
@Test public void testRegisterSchema() throws Exception { assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(), getKiji().getURI().toString(), "--register=" + mFile.toString(), "--interactive=false" )); assertEquals(mSimpleSchema, mTable.getSchema(Long.parseLong(mToolOutputLines[0]))); }
List all schemas in the table @return The Tool exit code @throws IOException in case of an error
b'/**\n * List all schemas in the table.\n *\n * @return The Tool exit code.\n * @throws IOException in case of an error.\n */'private int list() throws IOException { final KijiSchemaTable schemaTable = mKiji.getSchemaTable(); long id = 0; Schema schema = schemaTable.getSchema(id); while (null != schema) { getPrintStream().printf("%d: %s%n", id, schema.toString()); schema = schemaTable.getSchema(++id); } return SUCCESS; }
@Test public void testList() throws Exception { final long simpleSchemaId = getKiji().getSchemaTable().getOrCreateSchemaId(mSimpleSchema); assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(), getKiji().getURI().toString(), "--list")); assertTrue(mToolOutputStr.contains( String.format("%d: %s%n", simpleSchemaId, mSimpleSchema.toString()))); }
Lookup a schema @return Tool exit code @throws IOException in case of an error
b'/**\n * Lookup a schema.\n *\n * @return Tool exit code.\n * @throws IOException in case of an error.\n */'private int lookupSchema() throws IOException { final KijiSchemaTable table = mKiji.getSchemaTable(); final File file = new File(mLookupFlag); final Schema schema = new Schema.Parser().parse(file); final SchemaEntry sEntry = table.getSchemaEntry(schema); final long id = sEntry.getId(); final BytesKey hash = sEntry.getHash(); if (isInteractive()) { getPrintStream().print("Schema ID for the given schema is: "); } getPrintStream().println(id); if (isInteractive()) { getPrintStream().print("Schema hash for the given schema is: "); } getPrintStream().println(hash); return SUCCESS; }
@Test public void lookupSchema() throws Exception { final BytesKey hash = mTable.getSchemaHash(mSimpleSchema); final long id = mTable.getOrCreateSchemaId(mSimpleSchema); assertEquals(BaseTool.SUCCESS, runTool(new SchemaTableTool(), getKiji().getURI().toString(), "--lookup=" + mFile.toString(), "--interactive=false" )); assertEquals(id, Long.parseLong(mToolOutputLines[0])); assertEquals(hash, new BytesKey(ByteArrayFormatter.parseHex(mToolOutputLines[1], ':'))); }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseValidMapEmpty() throws Exception { final Map<String, String> kvs = mParser.parse(""); final Map<String, String> expected = ImmutableMap.<String, String>builder().build(); assertEquals(expected, kvs); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testNoAuthority() { try { KijiURI.newBuilder("kiji-hbase:///"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji-hbase:///' : ZooKeeper ensemble missing.", kurie.getMessage()); } }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseValidMapOneEntry() throws Exception { final Map<String, String> kvs = mParser.parse("key1=value1"); final Map<String, String> expected = ImmutableMap.<String, String>builder().put("key1", "value1").build(); assertEquals(expected, kvs); }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseValidMapManyEntries() throws Exception { final Map<String, String> kvs = mParser.parse("key1=value1 key2=value2 key3=value3"); final Map<String, String> expected = ImmutableMap.<String, String>builder() .put("key1", "value1") .put("key2", "value2") .put("key3", "value3") .build(); assertEquals(expected, kvs); }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseValidMapEmptySpaces() throws Exception { final Map<String, String> kvs = mParser.parse(" "); final Map<String, String> expected = ImmutableMap.<String, String>builder().build(); assertEquals(expected, kvs); }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseValidMapManySpaces() throws Exception { final Map<String, String> kvs = mParser.parse(" key1=value1 key2=value2 key3=value3 "); final Map<String, String> expected = ImmutableMap.<String, String>builder() .put("key1", "value1") .put("key2", "value2") .put("key3", "value3") .build(); assertEquals(expected, kvs); }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseInvalidMapNoEquals() throws Exception { try { final String input = "key1=value1 invalid key3=value3"; mParser.parse(input); fail(String.format("Space-separated parser should have caught an error in '%s'", input)); } catch (IOException ioe) { LOG.debug("Expected error: {}", ioe); } }
["('/**\\\\n * Parses a space-separated map into a Java map.\\\\n *\\\\n * @param input Space-separated map.\\\\n * @return the parsed Java map.\\\\n * @throws IOException on parse error.\\\\n */', '')"]
b'/**\n * Parses a space-separated map into a Java map.\n *\n * @param input Space-separated map.\n * @return the parsed Java map.\n * @throws IOException on parse error.\n */'public Map<String, String> parse(String input) throws IOException { final Map<String, String> kvs = Maps.newHashMap(); for (String pair: input.split(" ")) { if (pair.isEmpty()) { continue; } final String[] kvSplit = pair.split("=", 2); if (kvSplit.length != 2) { throw new IOException(String.format( "Invalid argument '%s' in space-separated map '%s'.", pair, input)); } final String key = kvSplit[0]; final String value = kvSplit[1]; final String existing = kvs.put(key, value); if (existing != null) { throw new IOException(String.format( "Duplicate key '%s' in space-separated map.'%s'.", key, input)); } } return kvs; }
@Test public void testParseInvalidMapDuplicateKey() throws Exception { try { final String input = "key1=value1 key1=value2"; mParser.parse(input); fail(String.format("Space-separated parser should have caught an error in '%s'", input)); } catch (IOException ioe) { LOG.debug("Expected error: {}", ioe); } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testTooLargeInt() throws Exception { try { ToolUtils.createEntityIdFromUserInputs("['dummy', 'str1', 'str2', 2147483648, 10]", mFormattedLayout); fail("Should fail with EntityIdException."); } catch (EntityIdException eie) { assertEquals("Invalid type for component 2147483648 at index 3 in kijiRowKey", eie.getMessage()); } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testTooLargeLong() throws Exception { try { ToolUtils.createEntityIdFromUserInputs("['dummy', 'str1', 'str2', 5, 9223372036854775808]", mFormattedLayout); fail("Should fail with EntityIdException."); } catch (IOException ioe) { assertEquals("Invalid JSON value: '9223372036854775808', expecting string, " + "int, long, or null.", ioe.getMessage()); } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testIntForLong() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout .getDesc().getKeysFormat()); final EntityId eid = factory.getEntityId("dummy", "str1", "str2", 5, 10); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs("['dummy', 'str1', 'str2', 5, 10]", mFormattedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testTooFewComponents() throws IOException { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat()); final EntityId eid = factory.getEntityId("dummy", "str1", "str2", 5, null); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs("['dummy', 'str1', 'str2', 5]", mFormattedLayout)); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsNoParen() { try { KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2:1234/instance/table/col"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji-hbase://zkhost1,zkhost2:1234/instance/table/col' : " + "Multiple ZooKeeper hosts must be parenthesized.", kurie.getMessage()); } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testNonNullFollowsNull() throws IOException { try { ToolUtils .createEntityIdFromUserInputs("['dummy', 'str1', 'str2', null, 5]", mFormattedLayout); fail("Should fail with EntityIdException."); } catch (EntityIdException eie) { assertEquals("Non null component follows null component", eie.getMessage()); } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testEmptyString() throws IOException { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat()); final EntityId eid = factory.getEntityId("", "", "", null, null); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs("['', '', '', null, null]", mFormattedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testASCIIChars() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat()); for (byte b = 32; b < 127; b++) { for (byte b2 = 32; b2 < 127; b2++) { final EntityId eid = factory.getEntityId(String.format( "dumm%sy", new String(new byte[]{b, b2}, "Utf-8")), "str1", "str2", 5, 10L); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mFormattedLayout)); } } }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testRawParserLoop() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mRawLayout.getDesc().getKeysFormat()); final EntityId eid = factory.getEntityIdFromHBaseRowKey(Bytes.toBytes("rawRowKey")); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mRawLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHashedParserLoop() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mHashedLayout.getDesc().getKeysFormat()); final EntityId eid = factory.getEntityId("hashedRowKey"); assertEquals(eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mHashedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHashPrefixedParserLoop() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mHashPrefixedLayout.getDesc().getKeysFormat()); final EntityId eid = factory.getEntityId("hashPrefixedRowKey"); assertEquals( eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mHashPrefixedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHBaseEIDtoRawEID() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mRawLayout.getDesc().getKeysFormat()); final EntityId reid = factory.getEntityId("rawEID"); final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(reid.getHBaseRowKey()); assertEquals(reid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mRawLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHBaseEIDtoHashedEID() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mHashedLayout.getDesc().getKeysFormat()); final EntityId heid = factory.getEntityId("hashedEID"); final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(heid.getHBaseRowKey()); assertEquals(heid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mHashedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHBaseEIDtoHashPrefixedEID() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat) mHashPrefixedLayout.getDesc().getKeysFormat()); final EntityId hpeid = factory.getEntityId("hashPrefixedEID"); final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(hpeid.getHBaseRowKey()); assertEquals(hpeid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mHashPrefixedLayout)); }
['(\'/**\\\\n * Parses a command-line flag specifying an entity ID.\\\\n *\\\\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\\\\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\\\\n * necessary. The prefix is not always necessary.\\\\n *\\\\n * @param entityFlag Command-line flag specifying an entity ID.\\\\n * @param layout Layout of the table describing the entity ID format.\\\\n * @return the entity ID as specified in the flags.\\\\n * @throws IOException on I/O error.\\\\n */\', \'\')', "('', '// HBase row key specification\\n')", "('', '// Kiji row key specification\\n')"]
b'/**\n * Parses a command-line flag specifying an entity ID.\n *\n * <li> HBase row key specifications must be prefixed with <code>"hbase=..."</code>\n * <li> Kiji row key specifications may be explicitly prefixed with <code>"kiji=..."</code> if\n * necessary. The prefix is not always necessary.\n *\n * @param entityFlag Command-line flag specifying an entity ID.\n * @param layout Layout of the table describing the entity ID format.\n * @return the entity ID as specified in the flags.\n * @throws IOException on I/O error.\n */'public static EntityId createEntityIdFromUserInputs(String entityFlag, KijiTableLayout layout) throws IOException { Preconditions.checkNotNull(entityFlag); final EntityIdFactory factory = EntityIdFactory.getFactory(layout); if (entityFlag.startsWith(HBASE_ROW_KEY_SPEC_PREFIX)) { // HBase row key specification final String hbaseSpec = entityFlag.substring(HBASE_ROW_KEY_SPEC_PREFIX.length()); final byte[] hbaseRowKey = parseBytesFlag(hbaseSpec); return factory.getEntityIdFromHBaseRowKey(hbaseRowKey); } else { // Kiji row key specification final String kijiSpec = entityFlag.startsWith(KIJI_ROW_KEY_SPEC_PREFIX) ? entityFlag.substring(KIJI_ROW_KEY_SPEC_PREFIX.length()) : entityFlag; return parseKijiRowKey(kijiSpec, factory, layout); } }
@Test public void testHBaseEIDtoFormattedEID() throws Exception { final EntityIdFactory factory = EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat()); final EntityId feid = factory.getEntityId("dummy", "str1", "str2", 5, 10); final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(feid.getHBaseRowKey()); assertEquals(feid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mFormattedLayout)); }
["('/** {@inheritDoc} */', '')", "('', '// In the case that we have enough information to generate a prefix, we will\\n')", '(\'\', "// construct a PrefixFilter that is AND\'ed with the RowFilter. This way,\\n")', "('', '// when the scan passes the end of the prefix, it can end the filtering\\n')", "('', '// process quickly.\\n')", "('', '// Define a regular expression that effectively creates a mask for the row\\n')", "('', '// key based on the key format and the components passed in. Prefix hashes\\n')", "('', '// are skipped over, and null components match any value.\\n')", "('', '// ISO-8859-1 is used so that numerals map to valid characters\\n')", "('', '// see http://stackoverflow.com/a/1387184\\n')", "('', '// Use the embedded flag (?s) to turn on single-line mode; this makes the\\n')", '(\'\', "// \'.\' match on line terminators. The RegexStringComparator uses the DOTALL\\n")', "('', '// flag during construction, but it does not use that flag upon\\n')", "('', '// deserialization. This bug has been fixed in HBASE-5667, part of the 0.95\\n')", "('', '// release.\\n')", "('', '// ^ matches the beginning of the string\\n')", "('', '// If all of the components included in the hash have been specified,\\n')", "('', '// then match on the value of the hash\\n')", "('', '// Write the hashed bytes to the prefix buffer\\n')", '(\'\', "// match any character exactly \'hash size\' number of times\\n")', "('', '// Only add to the prefix buffer until we hit a null component. We do this\\n')", "('', '// here, because the prefix is going to expect to have 0x00 component\\n')", "('', '// terminators, which we put in during this loop but not in the loop above.\\n')", "('', '// null integers can be excluded entirely if there are just nulls at\\n')", "('', '// the end of the EntityId, otherwise, match the correct number of\\n')", "('', '// bytes\\n')", "('', '// match each byte in the integer using a regex hex sequence\\n')", "('', '// null longs can be excluded entirely if there are just nulls at\\n')", "('', '// the end of the EntityId, otherwise, match the correct number of\\n')", "('', '// bytes\\n')", "('', '// match each byte in the long using a regex hex sequence\\n')", "('', '// match any non-zero character at least once, followed by a zero\\n')", "('', '// delimiter, or match nothing at all in case the component was at\\n')", "('', '// the end of the EntityId and skipped entirely\\n')", "('', '// FormattedEntityId converts a string component to UTF-8 bytes to\\n')", "('', '// create the HBase key. RegexStringComparator will convert the\\n')", "('', '// value it sees (ie, the HBase key) to a string using ISO-8859-1.\\n')", "('', '// Therefore, we need to write ISO-8859-1 characters to our regex so\\n')", "('', '// that the comparison happens correctly.\\n')", "('', '// $ matches the end of the string\\n')"]
b'/** {@inheritDoc} */'@Override public Filter toHBaseFilter(Context context) throws IOException { // In the case that we have enough information to generate a prefix, we will // construct a PrefixFilter that is AND'ed with the RowFilter. This way, // when the scan passes the end of the prefix, it can end the filtering // process quickly. boolean addPrefixFilter = false; ByteArrayOutputStream prefixBytes = new ByteArrayOutputStream(); // Define a regular expression that effectively creates a mask for the row // key based on the key format and the components passed in. Prefix hashes // are skipped over, and null components match any value. // ISO-8859-1 is used so that numerals map to valid characters // see http://stackoverflow.com/a/1387184 // Use the embedded flag (?s) to turn on single-line mode; this makes the // '.' match on line terminators. The RegexStringComparator uses the DOTALL // flag during construction, but it does not use that flag upon // deserialization. This bug has been fixed in HBASE-5667, part of the 0.95 // release. StringBuilder regex = new StringBuilder("(?s)^"); // ^ matches the beginning of the string if (null != mRowKeyFormat.getSalt()) { if (mRowKeyFormat.getSalt().getHashSize() > 0) { // If all of the components included in the hash have been specified, // then match on the value of the hash Object[] prefixComponents = getNonNullPrefixComponents(mComponents, mRowKeyFormat.getRangeScanStartIndex()); if (prefixComponents.length == mRowKeyFormat.getRangeScanStartIndex()) { ByteArrayOutputStream tohash = new ByteArrayOutputStream(); for (Object component : prefixComponents) { byte[] componentBytes = toBytes(component); tohash.write(componentBytes, 0, componentBytes.length); } byte[] hashed = Arrays.copyOfRange(Hasher.hash(tohash.toByteArray()), 0, mRowKeyFormat.getSalt().getHashSize()); for (byte hashedByte : hashed) { regex.append(String.format("\\x%02x", hashedByte & 0xFF)); } addPrefixFilter = true; // Write the hashed bytes to the prefix buffer prefixBytes.write(hashed, 0, hashed.length); } else { // match any character exactly 'hash size' number of times regex.append(".{").append(mRowKeyFormat.getSalt().getHashSize()).append("}"); } } } // Only add to the prefix buffer until we hit a null component. We do this // here, because the prefix is going to expect to have 0x00 component // terminators, which we put in during this loop but not in the loop above. boolean hitNullComponent = false; for (int i = 0; i < mComponents.length; i++) { final Object component = mComponents[i]; switch (mRowKeyFormat.getComponents().get(i).getType()) { case INTEGER: if (null == component) { // null integers can be excluded entirely if there are just nulls at // the end of the EntityId, otherwise, match the correct number of // bytes regex.append("(.{").append(Bytes.SIZEOF_INT).append("})?"); hitNullComponent = true; } else { byte[] tempBytes = toBytes((Integer) component); // match each byte in the integer using a regex hex sequence for (byte tempByte : tempBytes) { regex.append(String.format("\\x%02x", tempByte & 0xFF)); } if (!hitNullComponent) { prefixBytes.write(tempBytes, 0, tempBytes.length); } } break; case LONG: if (null == component) { // null longs can be excluded entirely if there are just nulls at // the end of the EntityId, otherwise, match the correct number of // bytes regex.append("(.{").append(Bytes.SIZEOF_LONG).append("})?"); hitNullComponent = true; } else { byte[] tempBytes = toBytes((Long) component); // match each byte in the long using a regex hex sequence for (byte tempByte : tempBytes) { regex.append(String.format("\\x%02x", tempByte & 0xFF)); } if (!hitNullComponent) { prefixBytes.write(tempBytes, 0, tempBytes.length); } } break; case STRING: if (null == component) { // match any non-zero character at least once, followed by a zero // delimiter, or match nothing at all in case the component was at // the end of the EntityId and skipped entirely regex.append("([^\\x00]+\\x00)?"); hitNullComponent = true; } else { // FormattedEntityId converts a string component to UTF-8 bytes to // create the HBase key. RegexStringComparator will convert the // value it sees (ie, the HBase key) to a string using ISO-8859-1. // Therefore, we need to write ISO-8859-1 characters to our regex so // that the comparison happens correctly. byte[] utfBytes = toBytes((String) component); String isoString = new String(utfBytes, Charsets.ISO_8859_1); regex.append(isoString).append("\\x00"); if (!hitNullComponent) { prefixBytes.write(utfBytes, 0, utfBytes.length); prefixBytes.write((byte) 0); } } break; default: throw new IllegalStateException("Unknown component type: " + mRowKeyFormat.getComponents().get(i).getType()); } } regex.append("$"); // $ matches the end of the string final RowFilter regexRowFilter = SchemaPlatformBridge.get().createRowFilterFromRegex(CompareOp.EQUAL, regex.toString()); if (addPrefixFilter) { return new FilterList(new PrefixFilter(prefixBytes.toByteArray()), regexRowFilter); } return regexRowFilter; }
@Test public void testHashIsCalculatedWhenAllHashComponentsAreSpecified() throws Exception { final int hashLength = 2; RowKeyFormat2.Builder builder = RowKeyFormat2.newBuilder() .setEncoding(RowKeyEncoding.FORMATTED) .setSalt(new HashSpec(HashType.MD5, hashLength, false)) .setRangeScanStartIndex(1); List<RowKeyComponent> components = ImmutableList.of( new RowKeyComponent("id", INTEGER), // this one is included in the hash new RowKeyComponent("ts", LONG)); // this one is not builder.setComponents(components); RowKeyFormat2 rowKeyFormat = builder.build(); EntityIdFactory factory = EntityIdFactory.getFactory(rowKeyFormat); FormattedEntityIdRowFilter filter = createFilter(rowKeyFormat, 100); Object[] componentValues = new Object[] { Integer.valueOf(100), Long.valueOf(900000L) }; runTest(rowKeyFormat, filter, factory, INCLUDE, componentValues); EntityId entityId = factory.getEntityId(componentValues); byte[] hbaseKey = entityId.getHBaseRowKey(); Filter hbaseFilter = filter.toHBaseFilter(null); // A row key with a different hash but the same first component should be // excluded by the filter. The hash is 0x9f0f hbaseKey[0] = (byte) 0x7F; hbaseKey[1] = (byte) 0xFF; boolean filtered = hbaseFilter.filterRowKey(hbaseKey, 0, hbaseKey.length); doInclusionAssert(rowKeyFormat, filter, entityId, hbaseFilter, hbaseKey, EXCLUDE); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleHostsMultiplePorts() { try { KijiURI.newBuilder("kiji-hbase://zkhost1:1234,zkhost2:2345/instance/table/col"); fail("An exception should have been thrown."); } catch (KijiURIException kurie) { assertEquals("Invalid Kiji URI: 'kiji-hbase://zkhost1:1234,zkhost2:2345/instance/table/col'" + " : Invalid ZooKeeper ensemble cluster identifier.", kurie.getMessage()); } }
["('/**\\\\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\\\\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\\\\n * the JVM to no longer be reachable.\\\\n *\\\\n * @param autoReferenceCountable to be registered to this reaper.\\\\n */', '')"]
b'/**\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\n * the JVM to no longer be reachable.\n *\n * @param autoReferenceCountable to be registered to this reaper.\n */'public void registerAutoReferenceCounted(AutoReferenceCounted autoReferenceCountable) { Preconditions.checkState(mIsOpen, "cannot register an AutoReferenceCounted to a closed AutoReferenceCountedReaper."); LOG.debug("Registering AutoReferenceCounted {}.", autoReferenceCountable); mReferences.add( new CloseablePhantomRef( autoReferenceCountable, mReferenceQueue, autoReferenceCountable.getCloseableResources()) ); }
@Test public void testReaperWillReapAutoReferenceCounted() throws Exception { CountDownLatch latch = new CountDownLatch(1); mReaper.registerAutoReferenceCounted(new LatchAutoReferenceCountable(latch)); System.gc(); // Force the phantom ref to be enqueued Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); }
["('/**\\\\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\\\\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\\\\n * the JVM to no longer be reachable.\\\\n *\\\\n * @param autoReferenceCountable to be registered to this reaper.\\\\n */', '')"]
b'/**\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\n * the JVM to no longer be reachable.\n *\n * @param autoReferenceCountable to be registered to this reaper.\n */'public void registerAutoReferenceCounted(AutoReferenceCounted autoReferenceCountable) { Preconditions.checkState(mIsOpen, "cannot register an AutoReferenceCounted to a closed AutoReferenceCountedReaper."); LOG.debug("Registering AutoReferenceCounted {}.", autoReferenceCountable); mReferences.add( new CloseablePhantomRef( autoReferenceCountable, mReferenceQueue, autoReferenceCountable.getCloseableResources()) ); }
@Test public void testCloserWillCloseAutoReferenceCountedInWeakSet() throws Exception { Set<AutoReferenceCounted> set = Collections.newSetFromMap( new MapMaker().weakKeys().<AutoReferenceCounted, Boolean>makeMap()); final CountDownLatch latch = new CountDownLatch(1); AutoReferenceCounted closeable = new LatchAutoReferenceCountable(latch); set.add(closeable); mReaper.registerAutoReferenceCounted(closeable); closeable = null; System.gc(); Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); }
["('/**\\\\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\\\\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\\\\n * the JVM to no longer be reachable.\\\\n *\\\\n * @param autoReferenceCountable to be registered to this reaper.\\\\n */', '')"]
b'/**\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\n * the JVM to no longer be reachable.\n *\n * @param autoReferenceCountable to be registered to this reaper.\n */'public void registerAutoReferenceCounted(AutoReferenceCounted autoReferenceCountable) { Preconditions.checkState(mIsOpen, "cannot register an AutoReferenceCounted to a closed AutoReferenceCountedReaper."); LOG.debug("Registering AutoReferenceCounted {}.", autoReferenceCountable); mReferences.add( new CloseablePhantomRef( autoReferenceCountable, mReferenceQueue, autoReferenceCountable.getCloseableResources()) ); }
@Test public void testCloserWillCloseAutoReferenceCountedInWeakCache() throws Exception { CountDownLatch latch = new CountDownLatch(1); final LoadingCache<CountDownLatch, AutoReferenceCounted> cache = CacheBuilder .newBuilder() .weakValues() .build(new CacheLoader<CountDownLatch, AutoReferenceCounted>() { @Override public AutoReferenceCounted load(CountDownLatch latch) throws Exception { AutoReferenceCounted closeable = new LatchAutoReferenceCountable(latch); mReaper.registerAutoReferenceCounted(closeable); return closeable; } }); cache.get(latch); // force creation System.gc(); Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); }
["('/**\\\\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\\\\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\\\\n * the JVM to no longer be reachable.\\\\n *\\\\n * @param autoReferenceCountable to be registered to this reaper.\\\\n */', '')"]
b'/**\n * Register an {@link AutoReferenceCounted} instance to be cleaned up by this\n * {@code AutoReferenceCountedReaper} when the {@link AutoReferenceCounted} is determined by\n * the JVM to no longer be reachable.\n *\n * @param autoReferenceCountable to be registered to this reaper.\n */'public void registerAutoReferenceCounted(AutoReferenceCounted autoReferenceCountable) { Preconditions.checkState(mIsOpen, "cannot register an AutoReferenceCounted to a closed AutoReferenceCountedReaper."); LOG.debug("Registering AutoReferenceCounted {}.", autoReferenceCountable); mReferences.add( new CloseablePhantomRef( autoReferenceCountable, mReferenceQueue, autoReferenceCountable.getCloseableResources()) ); }
@Test public void testWeakCacheWillBeCleanedUp() throws Exception { CountDownLatch latch = new CountDownLatch(2); final LoadingCache<CountDownLatch, AutoReferenceCounted> cache = CacheBuilder .newBuilder() .weakValues() .build(new CacheLoader<CountDownLatch, AutoReferenceCounted>() { @Override public AutoReferenceCounted load(CountDownLatch latch) throws Exception { AutoReferenceCounted closeable = new LatchAutoReferenceCountable(latch); mReaper.registerAutoReferenceCounted(closeable); return closeable; } }); cache.get(latch); System.gc(); cache.get(latch); System.gc(); Assert.assertTrue(latch.await(1, TimeUnit.SECONDS)); }
Reports whether the given schema is an optional type ie a union null Type @param schema The schema to test @return the optional type if the specified schema describes an optional type null otherwise
b'/**\n * Reports whether the given schema is an optional type (ie. a union { null, Type }).\n *\n * @param schema The schema to test.\n * @return the optional type, if the specified schema describes an optional type, null otherwise.\n */'public static Schema getOptionalType(Schema schema) { Preconditions.checkArgument(schema.getType() == Schema.Type.UNION); final List<Schema> types = schema.getTypes(); if (types.size() != 2) { return null; } if (types.get(0).getType() == Schema.Type.NULL) { return types.get(1); } else if (types.get(1).getType() == Schema.Type.NULL) { return types.get(0); } else { return null; } }
@Test public void testGetOptionalType() throws Exception { final List<Schema> unionSchemas = Lists.newArrayList( INT_SCHEMA, NULL_SCHEMA); final Schema optionalSchema = Schema.createUnion(unionSchemas); final Schema optionalReverseSchema = Schema.createUnion(Lists.reverse(unionSchemas)); // Ensure that the optional type is retrievable. assertEquals(INT_SCHEMA, AvroUtils.getOptionalType(optionalSchema)); assertEquals(INT_SCHEMA, AvroUtils.getOptionalType(optionalReverseSchema)); }
["('/**\\\\n * Reports whether the given schema is an optional type (ie. a union { null, Type }).\\\\n *\\\\n * @param schema The schema to test.\\\\n * @return the optional type, if the specified schema describes an optional type, null otherwise.\\\\n */', '')"]
b'/**\n * Reports whether the given schema is an optional type (ie. a union { null, Type }).\n *\n * @param schema The schema to test.\n * @return the optional type, if the specified schema describes an optional type, null otherwise.\n */'public static Schema getOptionalType(Schema schema) { Preconditions.checkArgument(schema.getType() == Schema.Type.UNION); final List<Schema> types = schema.getTypes(); if (types.size() != 2) { return null; } if (types.get(0).getType() == Schema.Type.NULL) { return types.get(1); } else if (types.get(1).getType() == Schema.Type.NULL) { return types.get(0); } else { return null; } }
@Test public void testGetNonOptionalType() throws Exception { final List<Schema> unionSchemas = Lists.newArrayList( INT_SCHEMA, STRING_SCHEMA, NULL_SCHEMA); final Schema nonOptionalSchema = Schema.createUnion(unionSchemas); // Ensure that null gets returned when the schema provided isn't an optional type. assertEquals(null, AvroUtils.getOptionalType(nonOptionalSchema)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateSchemaPairMissingField() throws Exception { final List<Schema.Field> readerFields = Lists.newArrayList( new Schema.Field("oldfield1", INT_SCHEMA, null, null)); final Schema reader = Schema.createRecord(readerFields); final AvroUtils.SchemaPairCompatibility expectedResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, reader, WRITER_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); // Test omitting a field. assertEquals(expectedResult, AvroUtils.checkReaderWriterCompatibility(reader, WRITER_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateSchemaPairMissingSecondField() throws Exception { final List<Schema.Field> readerFields = Lists.newArrayList( new Schema.Field("oldfield2", STRING_SCHEMA, null, null)); final Schema reader = Schema.createRecord(readerFields); final AvroUtils.SchemaPairCompatibility expectedResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, reader, WRITER_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); // Test omitting other field. assertEquals(expectedResult, AvroUtils.checkReaderWriterCompatibility(reader, WRITER_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateSchemaPairAllFields() throws Exception { final List<Schema.Field> readerFields = Lists.newArrayList( new Schema.Field("oldfield1", INT_SCHEMA, null, null), new Schema.Field("oldfield2", STRING_SCHEMA, null, null)); final Schema reader = Schema.createRecord(readerFields); final AvroUtils.SchemaPairCompatibility expectedResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, reader, WRITER_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); // Test with all fields. assertEquals(expectedResult, AvroUtils.checkReaderWriterCompatibility(reader, WRITER_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateSchemaNewFieldWithDefault() throws Exception { final List<Schema.Field> readerFields = Lists.newArrayList( new Schema.Field("oldfield1", INT_SCHEMA, null, null), new Schema.Field("newfield1", INT_SCHEMA, null, IntNode.valueOf(42))); final Schema reader = Schema.createRecord(readerFields); final AvroUtils.SchemaPairCompatibility expectedResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, reader, WRITER_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); // Test new field with default value. assertEquals(expectedResult, AvroUtils.checkReaderWriterCompatibility(reader, WRITER_SCHEMA)); }
['(\'/**\\\\n * Gets a builder configured with default Kiji URI fields.\\\\n *\\\\n * More precisely, the following defaults are initialized:\\\\n * <ul>\\\\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\\\\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n * (<tt>"default"</tt>).</li>\\\\n * <li>The table name and column names are explicitly left unset.</li>\\\\n * </ul>\\\\n *\\\\n * @return A builder configured with this Kiji URI.\\\\n */\', \'\')']
b'/**\n * Gets a builder configured with default Kiji URI fields.\n *\n * More precisely, the following defaults are initialized:\n * <ul>\n * <li>The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt></li>\n * <li>The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n * (<tt>"default"</tt>).</li>\n * <li>The table name and column names are explicitly left unset.</li>\n * </ul>\n *\n * @return A builder configured with this Kiji URI.\n */'public static HBaseKijiURIBuilder newBuilder() { return new HBaseKijiURIBuilder(); }
@Test public void testMultipleColumns() { final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2/default/table/col1,col2").build(); assertEquals("zkhost1", uri.getZookeeperQuorum().get(0)); assertEquals("zkhost2", uri.getZookeeperQuorum().get(1)); assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort()); assertEquals("default", uri.getInstance()); assertEquals("table", uri.getTable()); assertEquals(2, uri.getColumns().size()); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateSchemaNewField() throws Exception { final List<Schema.Field> readerFields = Lists.newArrayList( new Schema.Field("oldfield1", INT_SCHEMA, null, null), new Schema.Field("newfield1", INT_SCHEMA, null, null)); final Schema reader = Schema.createRecord(readerFields); final AvroUtils.SchemaPairCompatibility expectedResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.INCOMPATIBLE, reader, WRITER_SCHEMA, String.format( "Data encoded using writer schema:\n%s\n" + "will or may fail to decode using reader schema:\n%s\n", WRITER_SCHEMA.toString(true), reader.toString(true))); // Test new field without default value. assertEquals(expectedResult, AvroUtils.checkReaderWriterCompatibility(reader, WRITER_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidateArrayWriterSchema() throws Exception { final Schema validReader = Schema.createArray(STRING_SCHEMA); final Schema invalidReader = Schema.createMap(STRING_SCHEMA); final AvroUtils.SchemaPairCompatibility validResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, validReader, STRING_ARRAY_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); final AvroUtils.SchemaPairCompatibility invalidResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.INCOMPATIBLE, invalidReader, STRING_ARRAY_SCHEMA, String.format( "Data encoded using writer schema:\n%s\n" + "will or may fail to decode using reader schema:\n%s\n", STRING_ARRAY_SCHEMA.toString(true), invalidReader.toString(true))); assertEquals( validResult, AvroUtils.checkReaderWriterCompatibility(validReader, STRING_ARRAY_SCHEMA)); assertEquals( invalidResult, AvroUtils.checkReaderWriterCompatibility(invalidReader, STRING_ARRAY_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testValidatePrimitiveWriterSchema() throws Exception { final Schema validReader = Schema.create(Schema.Type.STRING); final AvroUtils.SchemaPairCompatibility validResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.COMPATIBLE, validReader, STRING_SCHEMA, AvroUtils.READER_WRITER_COMPATIBLE_MESSAGE); final AvroUtils.SchemaPairCompatibility invalidResult = new AvroUtils.SchemaPairCompatibility( AvroUtils.SchemaCompatibilityType.INCOMPATIBLE, INT_SCHEMA, STRING_SCHEMA, String.format( "Data encoded using writer schema:\n%s\n" + "will or may fail to decode using reader schema:\n%s\n", STRING_SCHEMA.toString(true), INT_SCHEMA.toString(true))); assertEquals( validResult, AvroUtils.checkReaderWriterCompatibility(validReader, STRING_SCHEMA)); assertEquals( invalidResult, AvroUtils.checkReaderWriterCompatibility(INT_SCHEMA, STRING_SCHEMA)); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testUnionReaderWriterSubsetIncompatibility() { final Schema unionWriter = Schema.createUnion( Lists.newArrayList(INT_SCHEMA, STRING_SCHEMA)); final Schema unionReader = Schema.createUnion( Lists.newArrayList(STRING_SCHEMA)); final SchemaPairCompatibility result = AvroUtils.checkReaderWriterCompatibility(unionReader, unionWriter); assertEquals(SchemaCompatibilityType.INCOMPATIBLE, result.getType()); }
["('/**\\\\n * Validates that the provided reader schema can be used to decode avro data written with the\\\\n * provided writer schema.\\\\n *\\\\n * @param reader schema to check.\\\\n * @param writer schema to check.\\\\n * @return a result object identifying any compatibility errors.\\\\n */', '')"]
b'/**\n * Validates that the provided reader schema can be used to decode avro data written with the\n * provided writer schema.\n *\n * @param reader schema to check.\n * @param writer schema to check.\n * @return a result object identifying any compatibility errors.\n */'public static SchemaPairCompatibility checkReaderWriterCompatibility( final Schema reader, final Schema writer ) { final SchemaCompatibilityType compatibility = new ReaderWriterCompatiblityChecker() .getCompatibility(reader, writer); final String message; switch (compatibility) { case INCOMPATIBLE: { message = String.format( "Data encoded using writer schema:%n%s%n" + "will or may fail to decode using reader schema:%n%s%n", writer.toString(true), reader.toString(true)); break; } case COMPATIBLE: { message = READER_WRITER_COMPATIBLE_MESSAGE; break; } default: throw new InternalKijiError("Unknown compatibility: " + compatibility); } return new SchemaPairCompatibility( compatibility, reader, writer, message); }
@Test public void testReaderWriterCompatibility() { for (ReaderWriter readerWriter : COMPATIBLE_READER_WRITER_TEST_CASES) { final Schema reader = readerWriter.getReader(); final Schema writer = readerWriter.getWriter(); LOG.debug("Testing compatibility of reader {} with writer {}.", reader, writer); final SchemaPairCompatibility result = AvroUtils.checkReaderWriterCompatibility(reader, writer); assertEquals(String.format( "Expecting reader %s to be compatible with writer %s, but tested incompatible.", reader, writer), SchemaCompatibilityType.COMPATIBLE, result.getType()); } }