Coder Social home page Coder Social logo

Comments (2)

jtaylor-sfdc avatar jtaylor-sfdc commented on July 30, 2024

Support the following syntax:


CREATE TABLE foo (
    host_name varchar,
    created_date date
    constraint my_pk primary key (host_name ASC, created_date DESC));

also this:


CREATE TABLE foo (
    id varchar PRIMARY KEY DESC,
    created_date date);

By default, the row key order would be ascending, but this could be overridden as shown above.

The implementation should all be mostly isolated to PDataType. However, the sort order would need to be stored in the SYSTEM.TABLE metadata table, in the row representing the column. The order value would cached in PColumn and passed through the PDataType methods. Check out the elegant way that Orderly does the writing, by having a mask on an Order enum and xor-ing like this:


/** The sort order of a row key, ascending or descending. */
public enum Order
{
  ASCENDING((byte)0),
  DESCENDING((byte)0xff);
  private final byte mask;
  Order(byte mask) { this.mask = mask; }
  /** Gets the byte mask associated with the sort order. When a 
   * serialized byte is XOR'd with the mask, the result is the same byte 
   * but sorted in the direction specified by the Order object. 
   * @see RowKey#serialize
   */
  byte mask() { return mask; }
}
public class FixedIntWritableRowKey extends RowKey
{
  private IntWritable iw;
  @Override
  public Class getSerializedClass() { return IntWritable.class; }
  @Override
  public int getSerializedLength(Object o) throws IOException {
    return Bytes.SIZEOF_INT;
  }
  @Override
  public void serialize(Object o, ImmutableBytesWritable w)
    throws IOException
  {
    byte[] b = w.get();
    int offset = w.getOffset();
    int i = ((IntWritable)o).get();
    Bytes.putInt(b, offset, i ^ Integer.MIN_VALUE ^ order.mask());
    RowKeyUtils.seek(w, Bytes.SIZEOF_INT);
  }
  @Override
  public void skip(ImmutableBytesWritable w) throws IOException {
    RowKeyUtils.seek(w, Bytes.SIZEOF_INT);
  }
  @Override
  public Object deserialize(ImmutableBytesWritable w) throws IOException {
    int offset = w.getOffset();
    byte[] s = w.get();
    int i = Bytes.toInt(s, offset) ^ Integer.MIN_VALUE ^ order.mask();
    RowKeyUtils.seek(w, Bytes.SIZEOF_INT);
    if (iw == null)
      iw = new IntWritable();
    iw.set(i);
    return iw;
  }
}

from phoenix.

jtaylor-sfdc avatar jtaylor-sfdc commented on July 30, 2024

Fixed by @simontoens, with a new record of a 78 file change list for his first Phoenix contribution! Thanks for the awesome work.

from phoenix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.