public void setOrder(String orderStr) {
   keySerializeInfo
       .getProperties()
       .setProperty(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_SORT_ORDER, orderStr);
 }
Example #2
0
  private void initJoinColumns(Map<String, TableDesc> tables) {
    // join columns may or may not present in cube;
    // here we don't modify 'allColumns' and 'dimensionColumns';
    // initDimensionColumns() will do the update
    for (LookupDesc lookup : this.lookups) {
      lookup.setTable(lookup.getTable().toUpperCase());
      TableDesc dimTable = tables.get(lookup.getTable());
      if (dimTable == null) {
        throw new IllegalStateException(
            "Table " + lookup.getTable() + " does not exist for " + this);
      }

      JoinDesc join = lookup.getJoin();
      if (join == null) continue;

      StringUtil.toUpperCaseArray(join.getForeignKey(), join.getForeignKey());
      StringUtil.toUpperCaseArray(join.getPrimaryKey(), join.getPrimaryKey());
      // primary key
      String[] pks = join.getPrimaryKey();
      TblColRef[] pkCols = new TblColRef[pks.length];
      for (int i = 0; i < pks.length; i++) {
        ColumnDesc col = dimTable.findColumnByName(pks[i]);
        if (col == null) {
          throw new IllegalStateException(
              "Can't find column " + pks[i] + " in table " + dimTable.getIdentity());
        }
        TblColRef colRef = new TblColRef(col);
        pks[i] = colRef.getName();
        pkCols[i] = colRef;
      }
      join.setPrimaryKeyColumns(pkCols);
      // foreign key
      TableDesc factTable = tables.get(this.factTable.toUpperCase());
      if (factTable == null) {
        throw new IllegalStateException("Fact table does not exist:" + this.getFactTable());
      }
      String[] fks = join.getForeignKey();
      TblColRef[] fkCols = new TblColRef[fks.length];
      for (int i = 0; i < fks.length; i++) {
        ColumnDesc col = factTable.findColumnByName(fks[i]);
        if (col == null) {
          throw new IllegalStateException(
              "Can't find column " + fks[i] + " in table " + this.getFactTable());
        }
        TblColRef colRef = new TblColRef(col);
        fks[i] = colRef.getName();
        fkCols[i] = colRef;
      }
      join.setForeignKeyColumns(fkCols);
      // Validate join in dimension
      if (pkCols.length != fkCols.length) {
        throw new IllegalStateException(
            "Primary keys("
                + lookup.getTable()
                + ")"
                + Arrays.toString(pks)
                + " are not consistent with Foreign keys("
                + this.getFactTable()
                + ") "
                + Arrays.toString(fks));
      }
      for (int i = 0; i < fkCols.length; i++) {
        if (!fkCols[i].getDatatype().equals(pkCols[i].getDatatype())) {
          throw new IllegalStateException(
              "Primary key "
                  + lookup.getTable()
                  + "."
                  + pkCols[i].getName()
                  + "."
                  + pkCols[i].getDatatype()
                  + " are not consistent with Foreign key "
                  + this.getFactTable()
                  + "."
                  + fkCols[i].getName()
                  + "."
                  + fkCols[i].getDatatype());
        }
      }
    }
  }
 /**
  * Returns the sort order of the key columns.
  *
  * @return null, which means ascending order for all key columns, or a String of the same length
  *     as key columns, that consists of only "+" (ascending order) and "-" (descending order).
  */
 @Explain(displayName = "sort order")
 public String getOrder() {
   return keySerializeInfo
       .getProperties()
       .getProperty(org.apache.hadoop.hive.serde.Constants.SERIALIZATION_SORT_ORDER);
 }