/*
 Map all unique pairs <family, name>  to index. Table name is part of TableRowkey, so we do
 not care about it
  */
 private void initColumnIndexes() throws SQLException {
   columnIndexes = new TreeMap(Bytes.BYTES_COMPARATOR);
   int columnIndex = 0;
   for (int index = 0; index < logicalNames.size(); index++) {
     PTable table = PhoenixRuntime.getTable(conn, logicalNames.get(index));
     List<PColumn> cls = table.getColumns();
     for (int i = 0; i < cls.size(); i++) {
       PColumn c = cls.get(i);
       byte[] family = new byte[0];
       if (c.getFamilyName() != null) // Skip PK column
       family = c.getFamilyName().getBytes();
       byte[] name = c.getName().getBytes();
       byte[] cfn = Bytes.add(family, QueryConstants.NAMESPACE_SEPARATOR_BYTES, name);
       if (!columnIndexes.containsKey(cfn)) {
         columnIndexes.put(cfn, new Integer(columnIndex));
         columnIndex++;
       }
     }
     byte[] emptyColumnFamily = SchemaUtil.getEmptyColumnFamily(table);
     byte[] cfn =
         Bytes.add(
             emptyColumnFamily,
             QueryConstants.NAMESPACE_SEPARATOR_BYTES,
             QueryConstants.EMPTY_COLUMN_BYTES);
     columnIndexes.put(cfn, new Integer(columnIndex));
     columnIndex++;
   }
 }
Пример #2
0
 protected PTable addDynamicColumns(List<ColumnDef> dynColumns, PTable theTable)
     throws SQLException {
   if (!dynColumns.isEmpty()) {
     List<PColumn> allcolumns = new ArrayList<PColumn>();
     List<PColumn> existingColumns = theTable.getColumns();
     // Need to skip the salting column, as it's added in the makePTable call below
     allcolumns.addAll(
         theTable.getBucketNum() == null
             ? existingColumns
             : existingColumns.subList(1, existingColumns.size()));
     // Position still based on with the salting columns
     int position = existingColumns.size();
     PName defaultFamilyName = PNameFactory.newName(SchemaUtil.getEmptyColumnFamily(theTable));
     for (ColumnDef dynColumn : dynColumns) {
       PName familyName = defaultFamilyName;
       PName name = PNameFactory.newName(dynColumn.getColumnDefName().getColumnName());
       String family = dynColumn.getColumnDefName().getFamilyName();
       if (family != null) {
         theTable.getColumnFamily(family); // Verifies that column family exists
         familyName = PNameFactory.newName(family);
       }
       allcolumns.add(
           new PColumnImpl(
               name,
               familyName,
               dynColumn.getDataType(),
               dynColumn.getMaxLength(),
               dynColumn.getScale(),
               dynColumn.isNull(),
               position,
               dynColumn.getSortOrder(),
               dynColumn.getArraySize(),
               null,
               false));
       position++;
     }
     theTable = PTableImpl.makePTable(theTable, allcolumns);
   }
   return theTable;
 }