Example #1
0
 public static String findExistingColumn(PTable table, List<PColumn> columns) {
   for (PColumn column : columns) {
     PName familyName = column.getFamilyName();
     if (familyName == null) {
       try {
         return table.getPKColumn(column.getName().getString()).getName().getString();
       } catch (ColumnNotFoundException e) {
         continue;
       }
     } else {
       try {
         return table
             .getColumnFamily(familyName.getString())
             .getColumn(column.getName().getString())
             .getName()
             .getString();
       } catch (ColumnFamilyNotFoundException e) {
         continue; // Shouldn't happen
       } catch (ColumnNotFoundException e) {
         continue;
       }
     }
   }
   return null;
 }
Example #2
0
 public static PName padTenantIdIfNecessary(
     RowKeySchema schema, boolean isSalted, PName tenantId) {
   int pkPos = isSalted ? 1 : 0;
   String tenantIdStr = tenantId.getString();
   Field field = schema.getField(pkPos);
   PDataType dataType = field.getDataType();
   boolean isFixedWidth = dataType.isFixedWidth();
   Integer maxLength = field.getMaxLength();
   if (isFixedWidth && maxLength != null) {
     if (tenantIdStr.length() < maxLength) {
       tenantIdStr = (String) dataType.pad(tenantIdStr, maxLength);
       return PNameFactory.newName(tenantIdStr);
     }
   }
   return tenantId;
 }