创建表— PUT ddl/database /:db/table /:table

Description

创建一个新的 HCatalog 表。有关更多信息,请参阅 Hive 文档CREATE TABLE

URL

http:// * www.myserver.com * /templeton/v1/ddl/database/ *:db * /table/ *:table *

Parameters

NameDescriptionRequired?Default
:db数据库名称。RequiredNone
:table新表名称。RequiredNone
group创建表时要使用的用户组。OptionalNone
permissions创建表时使用的权限字符串。OptionalNone
external允许您指定一个位置,以便 Hive 不使用此表的默认位置。Optionalfalse
ifNotExists如果为 true,则该表已经存在,则不会收到错误消息。Optionalfalse
commentComments 表。OptionalNone
columns列描述列表,包括名称,类型和可选 Comments。OptionalNone
partitionedBy用于分区表的列描述列表。像 columns 参数一样,这是名称,类型和 Comments 字段的列表。OptionalNone
clusteredBy一个对象,描述如何对表进行聚类,包括参数 columnNames,sortedBy 和 numberOfBuckets。 sortedBy 参数包括参数 columnName 和 order(升序为 ASC 或降序为 DESC)。有关更多信息,请参考下面的示例或Hive documentationOptionalNone
format存储格式描述,包括 rowFormat,storedAs 和 storedBy 的参数。有关更多信息,请参考下面的示例或Hive documentationOptionalNone
locationHDFS 路径。OptionalNone
tableProperties表属性名称和值(键/值对)的列表。OptionalNone

standard parameters也受支持。

Results

NameDescription
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 ResourcesWebHCat ReferenceWebHCat ManualHCatalog ManualHive Wiki 主页Hive 项目 site