Example #1
0
  /** Helper method for mutateTable */
  private static VoltTable.ColumnInfo growColumn(VoltTable.ColumnInfo oldCol) {
    VoltTable.ColumnInfo newCol = null;
    switch (oldCol.type) {
      case TINYINT:
        newCol = new VoltTable.ColumnInfo(oldCol.name, VoltType.SMALLINT);
        break;
      case SMALLINT:
        newCol = new VoltTable.ColumnInfo(oldCol.name, VoltType.INTEGER);
        break;
      case INTEGER:
        newCol = new VoltTable.ColumnInfo(oldCol.name, VoltType.BIGINT);
        break;
      case VARBINARY:
      case STRING:
        if (oldCol.size < 63) {
          newCol = new VoltTable.ColumnInfo(oldCol.name, oldCol.type);
          newCol.size = oldCol.size + 1;
        }
        // skip size 63 for now due to a bug
        if ((oldCol.size > 63) && (oldCol.size < VoltType.MAX_VALUE_LENGTH)) {
          newCol = new VoltTable.ColumnInfo(oldCol.name, oldCol.type);
          newCol.size = oldCol.size + 1;
        }
        break;
      default:
        // do nothing
        break;
    }

    if (newCol != null) {
      newCol.defaultValue = oldCol.defaultValue;
      newCol.nullable = oldCol.nullable;
      newCol.unique = oldCol.unique;
    }

    return newCol;
  }
Example #2
0
  /** Helper function for getTotallyRandomTable that makes random columns. */
  protected static VoltTable.ColumnInfo getRandomColumn(String name, Random rand) {
    VoltType[] allTypes = {
      VoltType.BIGINT,
      VoltType.DECIMAL,
      VoltType.FLOAT,
      VoltType.INTEGER,
      VoltType.SMALLINT,
      VoltType.STRING,
      VoltType.TIMESTAMP,
      VoltType.TINYINT,
      VoltType.VARBINARY
    };

    // random type
    VoltTable.ColumnInfo column =
        new VoltTable.ColumnInfo(name, allTypes[rand.nextInt(allTypes.length)]);

    // random sizes
    column.size = 0;
    if ((column.type == VoltType.VARBINARY) || (column.type == VoltType.STRING)) {
      // pick a column size with 50% inline and 50% out of line
      if (rand.nextBoolean()) {
        // pick a random number between 1 and 63 inclusive
        column.size = rand.nextInt(63) + 1;
      } else {
        // gaussian with stddev on 1024 (though offset by 64) and max of 1mb
        column.size =
            Math.min(64 + (int) (Math.abs(rand.nextGaussian()) * (1024 - 64)), 1024 * 1024);
      }
    }

    // nullable or default valued?
    Object defaultValue = null;
    if (rand.nextBoolean()) {
      column.nullable = true;
      defaultValue =
          VoltTypeUtil.getRandomValue(column.type, Math.max(column.size % 128, 1), 0.8, rand);
    } else {
      column.nullable = false;
      defaultValue =
          VoltTypeUtil.getRandomValue(column.type, Math.max(column.size % 128, 1), 0.0, rand);
      // no uniques for now, as the random fill becomes too slow
      // column.unique = (r.nextDouble() > 0.3); // 30% of non-nullable cols unique (15% total)
    }
    if (defaultValue != null) {
      column.defaultValue = String.valueOf(defaultValue);
    } else {
      column.defaultValue = null;
    }

    // these two columns need to be nullable with no default value
    if ((column.type == VoltType.VARBINARY) || (column.type == VoltType.DECIMAL)) {
      column.defaultValue = null;
      column.nullable = true;
    }

    assert (column.name != null);
    assert (column.size >= 0);
    if ((column.type == VoltType.STRING) || (column.type == VoltType.VARBINARY)) {
      assert (column.size >= 0);
    }

    return column;
  }