On this page
创建表— PUT ddl/database /:db/table /:table
Description
创建一个新的 HCatalog 表。有关更多信息,请参阅 Hive 文档CREATE TABLE。
URL
http://
* www.myserver.com * /templeton/v1/ddl/database/
*:db * /table/
*:table *
Parameters
Name | Description | Required? | Default |
---|---|---|---|
:db | 数据库名称。 | Required | None |
:table | 新表名称。 | Required | None |
group | 创建表时要使用的用户组。 | Optional | None |
permissions | 创建表时使用的权限字符串。 | Optional | None |
external | 允许您指定一个位置,以便 Hive 不使用此表的默认位置。 | Optional | false |
ifNotExists | 如果为 true,则该表已经存在,则不会收到错误消息。 | Optional | false |
comment | Comments 表。 | Optional | None |
columns | 列描述列表,包括名称,类型和可选 Comments。 | Optional | None |
partitionedBy | 用于分区表的列描述列表。像 columns 参数一样,这是名称,类型和 Comments 字段的列表。 | Optional | None |
clusteredBy | 一个对象,描述如何对表进行聚类,包括参数 columnNames,sortedBy 和 numberOfBuckets。 sortedBy 参数包括参数 columnName 和 order(升序为 ASC 或降序为 DESC)。有关更多信息,请参考下面的示例或Hive documentation。 | Optional | None |
format | 存储格式描述,包括 rowFormat,storedAs 和 storedBy 的参数。有关更多信息,请参考下面的示例或Hive documentation。 | Optional | None |
location | HDFS 路径。 | Optional | None |
tableProperties | 表属性名称和值(键/值对)的列表。 | Optional | None |
standard parameters也受支持。
Results
Name | Description |
---|---|
table | 新表名称。 |
database | 数据库名称。 |
Example
Curl Command
% curl -s -X PUT -HContent-type:application/json -d '{
"comment": "Best table made today",
"columns": [
{ "name": "id", "type": "bigint" },
{ "name": "price", "type": "float", "comment": "The unit price" } ],
"partitionedBy": [
{ "name": "country", "type": "string" } ],
"format": { "storedAs": "rcfile" } }' \
'http://localhost:50111/templeton/v1/ddl/database/default/table/test_table?user.name=ctdean'
Curl 命令(使用 clusteredBy)
% curl -s -X PUT -HContent-type:application/json -d '{
"comment": "Best table made today",
"columns": [
{ "name": "id", "type": "bigint"},
{ "name": "price", "type": "float", "comment": "The unit price" } ],
"partitionedBy": [
{ "name": "country", "type": "string" } ],
"clusteredBy": {
"columnNames": ["id"],
"sortedBy": [
{ "columnName": "id", "order": "ASC" } ],
"numberOfBuckets": 10 },
"format": {
"storedAs": "rcfile",
"rowFormat": {
"fieldsTerminatedBy": "\u0001",
"serde": {
"name": "org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe",
"properties": {
"key": "value" } } } }
} ' \
'http://localhost:50111/templeton/v1/ddl/database/default/table/test_table_c?user.name=ctdean'
JSON Output
{
"table": "test_table",
"database": "default"
}
JSON 输出(错误)
{
"statement": "use default; create table test_table_c(id bigint, price float comment ...",
"error": "unable to create table: test_table_c",
"exec": {
"stdout": "",
"stderr": "WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated...
Hive history file=/tmp/ctdean/hive_job_log_ctdean_201204051335_2016086186.txt
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in ...
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
OK
Time taken: 0.448 seconds
FAILED: Error in semantic analysis: Operation not supported. HCatalog doesn't allow Clustered By in create table.
",
"exitcode": 10
}
}
Navigation Links
上一个:GET ddl/database/:db/table/:table下一个:POST ddl/database/:db/table/:table
一般:DDL Resources – WebHCat Reference – WebHCat Manual – HCatalog Manual – Hive Wiki 主页 – Hive 项目 site