private static RowKeySchema buildSchema(int[] widths) {
    RowKeySchemaBuilder builder = new RowKeySchemaBuilder().setMinNullable(10);
    for (final int width : widths) {
      builder.addField(
          new PDatum() {
            @Override
            public boolean isNullable() {
              return false;
            }

            @Override
            public PDataType getDataType() {
              return PDataType.CHAR;
            }

            @Override
            public Integer getByteSize() {
              return width;
            }

            @Override
            public Integer getMaxLength() {
              return width;
            }

            @Override
            public Integer getScale() {
              return null;
            }

            @Override
            public ColumnModifier getColumnModifier() {
              return null;
            }
          });
    }
    return builder.build();
  }
Esempio n. 2
0
  public SkipScanFilterTest(
      List<List<KeyRange>> cnf, int[] widths, List<Expectation> expectations) {
    this.expectations = expectations;
    this.cnf = cnf;
    RowKeySchemaBuilder builder = new RowKeySchemaBuilder().setMinNullable(10);
    for (final int width : widths) {
      builder.addField(
          new PDatum() {

            @Override
            public boolean isNullable() {
              return false;
            }

            @Override
            public PDataType getDataType() {
              return PDataType.CHAR;
            }

            @Override
            public Integer getByteSize() {
              return width;
            }

            @Override
            public Integer getMaxLength() {
              return width;
            }

            @Override
            public Integer getScale() {
              return null;
            }
          });
    }
    skipper = new SkipScanFilter(cnf, builder.build());
  }
Esempio n. 3
0
  private void init(
      PName name,
      PTableType type,
      long timeStamp,
      long sequenceNumber,
      String pkName,
      List<PColumn> columns,
      PTableStats stats) {
    this.name = name;
    this.type = type;
    this.timeStamp = timeStamp;
    this.sequenceNumber = sequenceNumber;
    this.columnsByName = ArrayListMultimap.create(columns.size(), 1);
    this.pkName = pkName;
    List<PColumn> pkColumns = Lists.newArrayListWithExpectedSize(columns.size() - 1);
    PColumn[] allColumns = new PColumn[columns.size()];
    RowKeySchemaBuilder builder = new RowKeySchemaBuilder();
    for (int i = 0; i < allColumns.length; i++) {
      PColumn column = columns.get(i);
      allColumns[column.getPosition()] = column;
      PName familyName = column.getFamilyName();
      if (familyName == null) {
        pkColumns.add(column);
        builder.addField(column);
      }
      columnsByName.put(column.getName().getString(), column);
    }
    this.pkColumns = ImmutableList.copyOf(pkColumns);
    this.rowKeySchema = builder.setMinNullable(pkColumns.size()).build();
    this.allColumns = ImmutableList.copyOf(allColumns);

    // Two pass so that column order in column families matches overall column order
    // and to ensure that column family order is constant
    int maxExpectedSize = allColumns.length - pkColumns.size();
    // Maintain iteration order so that column families are ordered as they are listed
    Map<PName, List<PColumn>> familyMap = Maps.newLinkedHashMap();
    for (PColumn column : allColumns) {
      PName familyName = column.getFamilyName();
      if (familyName != null) {
        List<PColumn> columnsInFamily = familyMap.get(familyName);
        if (columnsInFamily == null) {
          columnsInFamily = Lists.newArrayListWithExpectedSize(maxExpectedSize);
          familyMap.put(familyName, columnsInFamily);
        }
        columnsInFamily.add(column);
      }
    }

    Iterator<Map.Entry<PName, List<PColumn>>> iterator = familyMap.entrySet().iterator();
    PColumnFamily[] families = new PColumnFamily[familyMap.size()];
    ImmutableMap.Builder<String, PColumnFamily> familyByString = ImmutableMap.builder();
    ImmutableSortedMap.Builder<byte[], PColumnFamily> familyByBytes =
        ImmutableSortedMap.orderedBy(Bytes.BYTES_COMPARATOR);
    for (int i = 0; i < families.length; i++) {
      Map.Entry<PName, List<PColumn>> entry = iterator.next();
      PColumnFamily family = new PColumnFamilyImpl(entry.getKey(), entry.getValue());
      families[i] = family;
      familyByString.put(family.getName().getString(), family);
      familyByBytes.put(family.getName().getBytes(), family);
    }
    this.families = ImmutableList.copyOf(families);
    this.familyByBytes = familyByBytes.build();
    this.familyByString = familyByString.build();
    this.stats = stats;
  }