Exemplo n.º 1
0
 public SingleTableColumnResolver(
     PhoenixConnection connection, NamedTableNode table, long timeStamp) throws SQLException {
   super(connection);
   List<PColumnFamily> families =
       Lists.newArrayListWithExpectedSize(table.getDynamicColumns().size());
   for (ColumnDef def : table.getDynamicColumns()) {
     if (def.getColumnDefName().getFamilyName() != null) {
       families.add(
           new PColumnFamilyImpl(
               PNameFactory.newName(def.getColumnDefName().getFamilyName()),
               Collections.<PColumn>emptyList()));
     }
   }
   Long scn = connection.getSCN();
   PTable theTable =
       new PTableImpl(
           connection.getTenantId(),
           table.getName().getSchemaName(),
           table.getName().getTableName(),
           scn == null ? HConstants.LATEST_TIMESTAMP : scn,
           families);
   theTable = this.addDynamicColumns(table.getDynamicColumns(), theTable);
   alias = null;
   tableRefs =
       ImmutableList.of(
           new TableRef(alias, theTable, timeStamp, !table.getDynamicColumns().isEmpty()));
 }
Exemplo n.º 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;
 }