@Test public void testClipLeft() throws Exception { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute("CREATE TABLE T1(K1 CHAR(1) NOT NULL, K2 VARCHAR, K3 VARCHAR, CONSTRAINT pk PRIMARY KEY (K1,K2,K3)) "); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); PTable table; RowKeySchema schema; table = pconn.getTable(new PTableKey(pconn.getTenantId(), "T1")); schema = table.getRowKeySchema(); KeyRange r, rLeft, expectedResult; r = KeyRange.getKeyRange(getKeyPart(table, "A", "B", "C"), true, getKeyPart(table, "B", "C"), true); rLeft = schema.clipLeft(0, r, 1, ptr); expectedResult = KeyRange.getKeyRange(getKeyPart(table, "A"), true, getKeyPart(table, "B"), true); r = KeyRange.getKeyRange(getKeyPart(table, "A", "B", "C"), true, getKeyPart(table, "B"), true); rLeft = schema.clipLeft(0, r, 1, ptr); expectedResult = KeyRange.getKeyRange(getKeyPart(table, "A"), true, getKeyPart(table, "B"), true); assertEquals(expectedResult, rLeft); rLeft = schema.clipLeft(0, r, 2, ptr); expectedResult = KeyRange.getKeyRange(getKeyPart(table, "A", "B"), true, getKeyPart(table, "B"), true); assertEquals(expectedResult, rLeft); r = KeyRange.getKeyRange(getKeyPart(table, "A", "B", "C"), true, KeyRange.UNBOUND, true); rLeft = schema.clipLeft(0, r, 2, ptr); expectedResult = KeyRange.getKeyRange(getKeyPart(table, "A", "B"), true, KeyRange.UNBOUND, false); assertEquals(expectedResult, rLeft); r = KeyRange.getKeyRange(KeyRange.UNBOUND, false, getKeyPart(table, "A", "B", "C"), true); rLeft = schema.clipLeft(0, r, 2, ptr); expectedResult = KeyRange.getKeyRange(KeyRange.UNBOUND, false, getKeyPart(table, "A", "B"), true); assertEquals(expectedResult, rLeft); }
public KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr) { if (spansToClip < 0) { throw new IllegalArgumentException("Cannot specify a negative spansToClip (" + spansToClip + ")"); } if (spansToClip == 0) { return keyRange; } byte[] lowerRange = keyRange.getLowerRange(); if (lowerRange != KeyRange.UNBOUND) { ptr.set(lowerRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(lowerRange, 0, ptr.getOffset() + ptr.getLength()); lowerRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upperRange = keyRange.getUpperRange(); if (upperRange != KeyRange.UNBOUND) { ptr.set(upperRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(upperRange, 0, ptr.getOffset() + ptr.getLength()); upperRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } return KeyRange.getKeyRange(lowerRange, true, upperRange, true); }
RowKeySchema extends ValueSchema { public KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr) { if (spansToClip < 0) { throw new IllegalArgumentException("Cannot specify a negative spansToClip (" + spansToClip + ")"); } if (spansToClip == 0) { return keyRange; } byte[] lowerRange = keyRange.getLowerRange(); if (lowerRange != KeyRange.UNBOUND) { ptr.set(lowerRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(lowerRange, 0, ptr.getOffset() + ptr.getLength()); lowerRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upperRange = keyRange.getUpperRange(); if (upperRange != KeyRange.UNBOUND) { ptr.set(upperRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(upperRange, 0, ptr.getOffset() + ptr.getLength()); upperRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } return KeyRange.getKeyRange(lowerRange, true, upperRange, true); } }
RowKeySchema extends ValueSchema { public KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr) { if (spansToClip < 0) { throw new IllegalArgumentException("Cannot specify a negative spansToClip (" + spansToClip + ")"); } if (spansToClip == 0) { return keyRange; } byte[] lowerRange = keyRange.getLowerRange(); if (lowerRange != KeyRange.UNBOUND) { ptr.set(lowerRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(lowerRange, 0, ptr.getOffset() + ptr.getLength()); lowerRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upperRange = keyRange.getUpperRange(); if (upperRange != KeyRange.UNBOUND) { ptr.set(upperRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(upperRange, 0, ptr.getOffset() + ptr.getLength()); upperRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } return KeyRange.getKeyRange(lowerRange, true, upperRange, true); } RowKeySchema(); protected  RowKeySchema(int minNullable, List<Field> fields, boolean rowKeyOrderOptimizable); }
RowKeySchema extends ValueSchema { public KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr) { if (spansToClip < 0) { throw new IllegalArgumentException("Cannot specify a negative spansToClip (" + spansToClip + ")"); } if (spansToClip == 0) { return keyRange; } byte[] lowerRange = keyRange.getLowerRange(); if (lowerRange != KeyRange.UNBOUND) { ptr.set(lowerRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(lowerRange, 0, ptr.getOffset() + ptr.getLength()); lowerRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upperRange = keyRange.getUpperRange(); if (upperRange != KeyRange.UNBOUND) { ptr.set(upperRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(upperRange, 0, ptr.getOffset() + ptr.getLength()); upperRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } return KeyRange.getKeyRange(lowerRange, true, upperRange, true); } RowKeySchema(); protected  RowKeySchema(int minNullable, List<Field> fields, boolean rowKeyOrderOptimizable); boolean rowKeyOrderOptimizable(); int getMaxFields(); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr, int position,int extraColumnSpan); Boolean iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr, int position); Boolean iterator(ImmutableBytesWritable srcPtr, ImmutableBytesWritable ptr, int position); Boolean iterator(byte[] src, ImmutableBytesWritable ptr, int position); int iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr); int iterator(byte[] src, ImmutableBytesWritable ptr); int iterator(ImmutableBytesWritable ptr); Boolean next(ImmutableBytesWritable ptr, int position, int maxOffset); int next(ImmutableBytesWritable ptr, int position, int maxOffset, int extraSpan); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean previous(ImmutableBytesWritable ptr, int position, int minOffset); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean reposition(ImmutableBytesWritable ptr, int oldPosition, int newPosition, int minOffset, int maxOffset); Boolean reposition(ImmutableBytesWritable ptr, int oldPosition, int newPosition, int minOffset, int maxOffset, int extraSpan); boolean position(ImmutableBytesWritable ptr, int position, int endPosition); int computeMaxSpan(int pkPos, KeyRange result, ImmutableBytesWritable ptr); int computeMinSpan(int pkPos, KeyRange keyRange, ImmutableBytesWritable ptr); KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr); }
RowKeySchema extends ValueSchema { public KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr) { if (spansToClip < 0) { throw new IllegalArgumentException("Cannot specify a negative spansToClip (" + spansToClip + ")"); } if (spansToClip == 0) { return keyRange; } byte[] lowerRange = keyRange.getLowerRange(); if (lowerRange != KeyRange.UNBOUND) { ptr.set(lowerRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(lowerRange, 0, ptr.getOffset() + ptr.getLength()); lowerRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } byte[] upperRange = keyRange.getUpperRange(); if (upperRange != KeyRange.UNBOUND) { ptr.set(upperRange); this.position(ptr, pkPos, pkPos+spansToClip-1); ptr.set(upperRange, 0, ptr.getOffset() + ptr.getLength()); upperRange = ByteUtil.copyKeyBytesIfNecessary(ptr); } return KeyRange.getKeyRange(lowerRange, true, upperRange, true); } RowKeySchema(); protected  RowKeySchema(int minNullable, List<Field> fields, boolean rowKeyOrderOptimizable); boolean rowKeyOrderOptimizable(); int getMaxFields(); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr, int position,int extraColumnSpan); Boolean iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr, int position); Boolean iterator(ImmutableBytesWritable srcPtr, ImmutableBytesWritable ptr, int position); Boolean iterator(byte[] src, ImmutableBytesWritable ptr, int position); int iterator(byte[] src, int srcOffset, int srcLength, ImmutableBytesWritable ptr); int iterator(byte[] src, ImmutableBytesWritable ptr); int iterator(ImmutableBytesWritable ptr); Boolean next(ImmutableBytesWritable ptr, int position, int maxOffset); int next(ImmutableBytesWritable ptr, int position, int maxOffset, int extraSpan); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean previous(ImmutableBytesWritable ptr, int position, int minOffset); @edu.umd.cs.findbugs.annotations.SuppressWarnings( value="NP_BOOLEAN_RETURN_NULL", justification="Designed to return null.") Boolean reposition(ImmutableBytesWritable ptr, int oldPosition, int newPosition, int minOffset, int maxOffset); Boolean reposition(ImmutableBytesWritable ptr, int oldPosition, int newPosition, int minOffset, int maxOffset, int extraSpan); boolean position(ImmutableBytesWritable ptr, int position, int endPosition); int computeMaxSpan(int pkPos, KeyRange result, ImmutableBytesWritable ptr); int computeMinSpan(int pkPos, KeyRange keyRange, ImmutableBytesWritable ptr); KeyRange clipLeft(int pkPos, KeyRange keyRange, int spansToClip, ImmutableBytesWritable ptr); static final RowKeySchema EMPTY_SCHEMA; }