共计 5239 个字符,预计需要花费 14 分钟才能阅读完成。
疑难 :
hive not null,是不是感觉 not null 是基于 column 的,所以就感觉 not null 是 column 中的一个字段,道歉,还真不是,口说无凭,上代码看一下
表格信息:
// 表
private String tableName; // required
// db
private String dbName; // required
// 表的所属,基于用于、者角色或者组
private String owner; // required
// 表创立事件
private int createTime; // required
// 最初拜访工夫
private int lastAccessTime; // required
// 保留字段,默认 0
private int retention; // required
// 存储相干,location,inputformat,outputformat, 序列化反序列化器
private StorageDescriptor sd; // required
// 这个就是列信息了
private List<FieldSchema> partitionKeys; // required
// table properties 信息
private Map<String,String> parameters; // required
// 视图相干
private String viewOriginalText; // required
private String viewExpandedText; // required
// 表类型,治理表、内部表、虚构视图和物化视图
private String tableType; // required
// 表的权限相干
private PrincipalPrivilegeSet privileges; // optional
// session 级别的长期表,create temporary table txx(id int);
private boolean temporary; // optional
// rewrite 简略来说其实就是一个 SQL 能不能要应用物化视图来优化查问
private boolean rewriteEnabled; // optional
// 物化视图相干,物化视图关联的表等等
private CreationMetadata creationMetadata; // optional
// 默认是 hive
private String catName; // optional
// 用户、角色或者所属组
private PrincipalType ownerType; // optional
FieldSchema 列信息:
// 列名称
private String name; // required
// 列类型
private String type; // required
// 形容
private String comment; // required
是不是列中没有 not null 信息
设计
创立表的时候 ,如果配置了主键、外键、惟一索引、not null、默认值和自定义取值束缚 ,都会走如下接口:
@Override
public void createTableWithConstraints(Table table,
List<SQLPrimaryKey> primaryKeys,
List<SQLForeignKey> foreignKeys,
List<SQLUniqueConstraint> uniqueConstraints,
List<SQLNotNullConstraint> notNullConstraints,
List<SQLDefaultConstraint> defaultConstraints,
List<SQLCheckConstraint> checkConstraints)
throws AlreadyExistsException, InvalidObjectException, MetaException, NoSuchObjectException, TException {LOG.info("edap createTableWithConstraints -> primaryKeys : {}, foreignKeys : {}, uniqueConstraints : {}, notNullConstraints : {}, defaultConstraints : {}, checkConstraints : {}",
primaryKeys, foreignKeys, uniqueConstraints, notNullConstraints, defaultConstraints, checkConstraints);
throw new UnsupportedOperationException("createTableWithConstraints is not supported");
}
// ALTER TABLE t_user1 CHANGE COLUMN id id string CONSTRAINT id NOT NULL ENABLE;
// 不反对 ALTER TABLE t_user1,t_user2 CHANGE COLUMN id id string CONSTRAINT id NOT NULL ENABLE; 所以 List<SQLNotNullConstraint> 中只能有一个雷同的 db 和 table
@Override
public void addNotNullConstraint(List<SQLNotNullConstraint> notNullConstraints)
throws MetaException, NoSuchObjectException, TException {LOG.info("edap addNotNullConstraint : notNullConstraints : {}", notNullConstraints);
}
@Override
public List<SQLNotNullConstraint> getNotNullConstraints(NotNullConstraintsRequest notNullConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
对应的获取元数据信息调用的接口是如下接口:
@Override
public List<SQLPrimaryKey> getPrimaryKeys(PrimaryKeysRequest primaryKeysRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
@Override
public List<SQLForeignKey> getForeignKeys(ForeignKeysRequest foreignKeysRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
@Override
public List<SQLUniqueConstraint> getUniqueConstraints(UniqueConstraintsRequest uniqueConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
@Override
public List<SQLNotNullConstraint> getNotNullConstraints(NotNullConstraintsRequest notNullConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
@Override
public List<SQLDefaultConstraint> getDefaultConstraints(DefaultConstraintsRequest defaultConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
@Override
public List<SQLCheckConstraint> getCheckConstraints(CheckConstraintsRequest checkConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
只剖析 SQLNotNullConstraint 的构造:
@Override
public List<SQLNotNullConstraint> getNotNullConstraints(NotNullConstraintsRequest notNullConstraintsRequest)
throws MetaException, NoSuchObjectException, TException {return null;}
SQLNotNullConstraint 构造如下 :
// 默认 hive 即可
private String catName; // required
// db
private String table_db; // required
// 表名
private String table_name; // required
// 列名
private String column_name; // required
// 束缚名称,比如说:ALTER TABLE t_user2 CHANGE COLUMN id id1 int CONSTRAINT id_not_null NOT NULL ENABLE;
private String nn_name; // required
// 是否开启 not null 的束缚,开启为 true,DISABLE NOVALIDATE 为 false
private boolean enable_cstr; // required
// 这个字段以后只反对 false NOVALIDATE,不反对 VALIDATE
private boolean validate_cstr; // required
// 是否将束缚用于查问优化
private boolean rely_cstr; // required
简略理解:
主键束缚:PRIMARY KEY
取值唯一性束缚:UNIQUE
非空值束缚:NOT NULL
默认值束缚:DEFAULT [default_value]
自定义取值束缚:CHECK [check_expression]
敞开束缚(能够对束缚列的数据进行批改):DISABLE NOVALIDATE
是否将束缚用于查问优化:RELY/NORELY
测试后果:
NOT NULL :
notNullConstraints : [SQLNotNullConstraint(catName:hive, table_db:default, table_name:constraints1, column_name:id1, nn_name:null, enable_cstr:true, validate_cstr:false, rely_cstr:false)]
NOT NULL ENABLE :
notNullConstraints : [SQLNotNullConstraint(catName:hive, table_db:default, table_name:constraints1, column_name:id1, nn_name:null, enable_cstr:true, validate_cstr:false, rely_cstr:false)]
DISABLE NOVALIDATE RELY :
notNullConstraints : [SQLNotNullConstraint(catName:hive, table_db:default, table_name:constraints1, column_name:id1, nn_name:null, enable_cstr:false, validate_cstr:false, rely_cstr:true)]
DISABLE NOVALIDATE NORELY :
notNullConstraints : [SQLNotNullConstraint(catName:hive, table_db:default, table_name:constraints1, column_name:id1, nn_name:null, enable_cstr:false, validate_cstr:false, rely_cstr:false)]
正文完