public Object getFieldValue(_Fields field) { switch (field) { case CAT_NAME: return getCatName(); case TABLE_DB: return getTable_db(); case TABLE_NAME: return getTable_name(); case COLUMN_NAME: return getColumn_name(); case KEY_SEQ: return getKey_seq(); case UK_NAME: return getUk_name(); case ENABLE_CSTR: return isEnable_cstr(); case VALIDATE_CSTR: return isValidate_cstr(); case RELY_CSTR: return isRely_cstr(); } throw new IllegalStateException(); }
@Override public void read(org.apache.thrift.protocol.TProtocol prot, UniqueConstraintsResponse struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; { org.apache.thrift.protocol.TList _list349 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, iprot.readI32()); struct.uniqueConstraints = new ArrayList<SQLUniqueConstraint>(_list349.size); SQLUniqueConstraint _elem350; for (int _i351 = 0; _i351 < _list349.size; ++_i351) { _elem350 = new SQLUniqueConstraint(); _elem350.read(iprot); struct.uniqueConstraints.add(_elem350); } } struct.setUniqueConstraintsIsSet(true); } }
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case CAT_NAME: return isSetCatName(); case TABLE_DB: return isSetTable_db(); case TABLE_NAME: return isSetTable_name(); case COLUMN_NAME: return isSetColumn_name(); case KEY_SEQ: return isSetKey_seq(); case UK_NAME: return isSetUk_name(); case ENABLE_CSTR: return isSetEnable_cstr(); case VALIDATE_CSTR: return isSetValidate_cstr(); case RELY_CSTR: return isSetRely_cstr(); } throw new IllegalStateException(); }
@Override public int compare(SQLUniqueConstraint o1, SQLUniqueConstraint o2) { int keyNameComp = o1.getUk_name().compareTo(o2.getUk_name()); if (keyNameComp == 0) { return Integer.compare(o1.getKey_seq(), o2.getKey_seq()); } return keyNameComp; } });
/** * Performs a deep copy on <i>other</i>. */ public SQLUniqueConstraint(SQLUniqueConstraint other) { __isset_bitfield = other.__isset_bitfield; if (other.isSetCatName()) { this.catName = other.catName; } if (other.isSetTable_db()) { this.table_db = other.table_db; } if (other.isSetTable_name()) { this.table_name = other.table_name; } if (other.isSetColumn_name()) { this.column_name = other.column_name; } this.key_seq = other.key_seq; if (other.isSetUk_name()) { this.uk_name = other.uk_name; } this.enable_cstr = other.enable_cstr; this.validate_cstr = other.validate_cstr; this.rely_cstr = other.rely_cstr; }
public UniqueConstraint(List<SQLUniqueConstraint> uks, String tableName, String databaseName) { this.tableName = tableName; this.databaseName = databaseName; uniqueConstraints = new TreeMap<String, List<UniqueConstraintCol>>(); if (uks == null) { return; } for (SQLUniqueConstraint uk : uks) { if (uk.getTable_db().equalsIgnoreCase(databaseName) && uk.getTable_name().equalsIgnoreCase(tableName)) { UniqueConstraintCol currCol = new UniqueConstraintCol( uk.getColumn_name(), uk.getKey_seq()); String constraintName = uk.getUk_name(); if (uniqueConstraints.containsKey(constraintName)) { uniqueConstraints.get(constraintName).add(currCol); } else { List<UniqueConstraintCol> currList = new ArrayList<UniqueConstraintCol>(); currList.add(currCol); uniqueConstraints.put(constraintName, currList); } } } }
List<SQLUniqueConstraint> uniqueConstraintCols = req.getUniqueConstraintCols(); String constraintName = (uniqueConstraintCols != null && uniqueConstraintCols.size() > 0) ? uniqueConstraintCols.get(0).getUk_name() : "null"; startFunction("add_unique_constraint", ": " + constraintName); boolean success = false; Exception ex = null; if (!uniqueConstraintCols.isEmpty() && !uniqueConstraintCols.get(0).isSetCatName()) { String defaultCat = getDefaultCatalog(conf); uniqueConstraintCols.forEach(pk -> pk.setCatName(defaultCat)); if (uniqueConstraintCols.get(i).getUk_name() == null) { uniqueConstraintCols.get(i).setUk_name(constraintNames.get(i));
/*** * @param addUniqueConstraintEvent add unique constraint event * @throws MetaException */ @Override public void onAddUniqueConstraint(AddUniqueConstraintEvent addUniqueConstraintEvent) throws MetaException { List<SQLUniqueConstraint> cols = addUniqueConstraintEvent.getUniqueConstraintCols(); if (cols.size() > 0) { AddUniqueConstraintMessage msg = MessageBuilder.getInstance() .buildAddUniqueConstraintMessage(addUniqueConstraintEvent.getUniqueConstraintCols()); NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_UNIQUECONSTRAINT.toString(), msgEncoder.getSerializer().serialize(msg) ); event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(cols.get(0).getTable_db()); event.setTableName(cols.get(0).getTable_name()); process(event, addUniqueConstraintEvent); } }
String actualDbName = context.isDbNameEmpty() ? uks.get(0).getTable_db() : context.dbName; String actualTblName = context.isTableNameEmpty() ? uks.get(0).getTable_name() : context.tableName; uk.setTable_db(actualDbName); uk.setTable_name(actualTblName);
private boolean isUniqueConstraintsAlreadyLoaded(String uksMsgString) throws Exception { AddUniqueConstraintMessage msg = deserializer.getAddUniqueConstraintMessage(uksMsgString); List<SQLUniqueConstraint> uksInMsg = msg.getUniqueConstraints(); if (uksInMsg.isEmpty()) { return true; } String dbName = StringUtils.isBlank(dbNameToLoadIn) ? uksInMsg.get(0).getTable_db() : dbNameToLoadIn; List<SQLUniqueConstraint> uks; try { uks = context.hiveDb.getUniqueConstraintList(dbName, uksInMsg.get(0).getTable_name()); } catch (NoSuchObjectException e) { return false; } return ((uks != null) && !uks.isEmpty()); }
ukSignature.append( generateColNameTypeSignature( uk.getColumn_name(), getColumnFromTableColumns(tableCols, uk.getColumn_name()).getType())); if (j + 1 < refTableUniqueConstraints.size()) { if (!refTableUniqueConstraints.get(j + 1).getUk_name().equals( refTableUniqueConstraints.get(j).getUk_name())) { validPKsOrUnique.add(ukSignature.toString()); ukSignature = new StringBuilder();
public SQLUniqueConstraint deepCopy() { return new SQLUniqueConstraint(this); }
@Override public void addUniqueConstraint(List<SQLUniqueConstraint> uniqueConstraintCols) throws NoSuchObjectException, MetaException, TException { if (!uniqueConstraintCols.isEmpty() && !uniqueConstraintCols.get(0).isSetCatName()) { String defaultCat = getDefaultCatalog(conf); uniqueConstraintCols.forEach(uc -> uc.setCatName(defaultCat)); } client.add_unique_constraint(new AddUniqueConstraintRequest(uniqueConstraintCols)); }
private UniqueConstraint getUniqueConstraints(String dbName, String tblName, boolean onlyReliable) throws HiveException { try { List<SQLUniqueConstraint> uniqueConstraints = getMSC().getUniqueConstraints( new UniqueConstraintsRequest(getDefaultCatalog(conf), dbName, tblName)); if (onlyReliable && uniqueConstraints != null && !uniqueConstraints.isEmpty()) { uniqueConstraints = uniqueConstraints.stream() .filter(uk -> uk.isRely_cstr()) .collect(Collectors.toList()); } return new UniqueConstraint(uniqueConstraints, tblName, dbName); } catch (Exception e) { throw new HiveException(e); } }
for (SQLForeignKey fkcol : foreignKeys) fkcol.setCatName(tbl.getCatName()); if (uniqueConstraints != null && !uniqueConstraints.isEmpty() && !uniqueConstraints.get(0).isSetCatName()) { for (SQLUniqueConstraint uccol : uniqueConstraints) uccol.setCatName(tbl.getCatName()); uniqueConstraintSize = uniqueConstraints.size(); for (int i = 0; i < uniqueConstraintSize; i++) { if (uniqueConstraints.get(i).getUk_name() == null) { uniqueConstraints.get(i).setUk_name(constraintNames.get(primaryKeySize + foreignKeySize + i)); if (!uniqueConstraints.get(i).isSetCatName()) uniqueConstraints.get(i).setCatName(tbl.getCatName());
/*** * @param addUniqueConstraintEvent add unique constraint event * @throws MetaException */ @Override public void onAddUniqueConstraint(AddUniqueConstraintEvent addUniqueConstraintEvent) throws MetaException { List<SQLUniqueConstraint> cols = addUniqueConstraintEvent.getUniqueConstraintCols(); if (cols.size() > 0) { NotificationEvent event = new NotificationEvent(0, now(), EventType.ADD_UNIQUECONSTRAINT.toString(), msgFactory .buildAddUniqueConstraintMessage(addUniqueConstraintEvent.getUniqueConstraintCols()).toString()); event.setCatName(cols.get(0).isSetCatName() ? cols.get(0).getCatName() : DEFAULT_CATALOG_NAME); event.setDbName(cols.get(0).getTable_db()); event.setTableName(cols.get(0).getTable_name()); process(event, addUniqueConstraintEvent); } }
return false; boolean this_present_catName = true && this.isSetCatName(); boolean that_present_catName = true && that.isSetCatName(); if (this_present_catName || that_present_catName) { if (!(this_present_catName && that_present_catName)) boolean this_present_table_db = true && this.isSetTable_db(); boolean that_present_table_db = true && that.isSetTable_db(); if (this_present_table_db || that_present_table_db) { if (!(this_present_table_db && that_present_table_db)) boolean this_present_table_name = true && this.isSetTable_name(); boolean that_present_table_name = true && that.isSetTable_name(); if (this_present_table_name || that_present_table_name) { if (!(this_present_table_name && that_present_table_name)) boolean this_present_column_name = true && this.isSetColumn_name(); boolean that_present_column_name = true && that.isSetColumn_name(); if (this_present_column_name || that_present_column_name) { if (!(this_present_column_name && that_present_column_name)) boolean this_present_uk_name = true && this.isSetUk_name(); boolean that_present_uk_name = true && that.isSetUk_name(); if (this_present_uk_name || that_present_uk_name) { if (!(this_present_uk_name && that_present_uk_name))
@Override public int compare(SQLUniqueConstraint o1, SQLUniqueConstraint o2) { int keyNameComp = o1.getUk_name().compareTo(o2.getUk_name()); if (keyNameComp == 0) { return Integer.compare(o1.getKey_seq(), o2.getKey_seq()); } return keyNameComp; } });
ukSignature.append( generateColNameTypeSignature( uk.getColumn_name(), getColumnFromTableColumns(tableCols, uk.getColumn_name()).getType())); if (j + 1 < refTableUniqueConstraints.size()) { if (!refTableUniqueConstraints.get(j + 1).getUk_name().equals( refTableUniqueConstraints.get(j).getUk_name())) { validPKsOrUnique.add(ukSignature.toString()); ukSignature = new StringBuilder();
private static void constraintInfosToUniqueConstraints(String catName, String databaseName, String tableName, List<ConstraintInfo> uniqueInfos, List<SQLUniqueConstraint> uniqueConstraints) { int i = 1; for (ConstraintInfo uniqueInfo : uniqueInfos) { uniqueConstraints.add(new SQLUniqueConstraint(catName, databaseName, tableName, uniqueInfo.colName, i++, uniqueInfo.constraintName, uniqueInfo.enable, uniqueInfo.validate, uniqueInfo.rely)); } }