1. 程式人生 > >Hive Beeline使用

Hive Beeline使用

 

原文連結:https://blog.csdn.net/huanggang028/article/details/44591663

 

Hive Beeline的推出時  !quit

 

 

 

 

Hive Beeline使用

2015年03月24日 14:57:13 huanggang028 閱讀數:66269更多

個人分類: hive

HiveServer2提供了一個新的命令列工具Beeline,它是基於SQLLine CLI的JDBC客戶端。關於SQLLine的的知識,可以參考這個網站:http://sqlline.sourceforge.net/#manual

Beeline工作模式有兩種,即本地嵌入模式和遠端模式。嵌入模式情況下,它返回一個嵌入式的Hive(類似於Hive CLI)。而遠端模式則是通過Thrift協議與某個單獨的HiveServer2程序進行連線通訊。

下面給一個簡單的登入Beeline的使用例項:

 

 
  1. % bin/beeline

  2. Hive version 0.11.0-SNAPSHOT by Apache

  3. beeline> !connect jdbc:hive2://localhost:10000/default

  4. !connect jdbc:hive2://localhost:10000/default

  5. Connecting to jdbc:hive2://localhost:10000/default

  6. Connected to: Hive (version 0.10.0)

  7. Driver: Hive (version 0.10.0-SNAPSHOT)

  8. Transaction isolation: TRANSACTION_REPEATABLE_READ

  9. 0: jdbc:hive2://localhost:10000> show tables;

  10. show tables;

  11. +-------------------+

  12. | tab_name |

  13. +-------------------+

  14. | primitives |

  15. | src |

  16. | src1 |

  17. | src_json |

  18. | src_sequencefile |

  19. | src_thrift |

  20. | srcbucket |

  21. | srcbucket2 |

  22. | srcpart |

  23. +-------------------+

  24. 9 rows selected (1.079 seconds)


我們專案在使用的過程中,因為整合了Hamza的許可權控制, 使用的時候需要傳入使用者名稱和密碼,(常用的方式有單次查詢-e,也可以把命令寫到一個檔案中-f),遠端連線到HiveServer2:

beeline -u "jdbc:hive2://hadoop1:10000/hamza_group_1" --hivevar hamza.usr="hamza_group" --hivevar hamza.passwd="hMyLXJ6uddQSy1WU" --color=true;

退出beeline命令列則是!quit, 很多命令都是前面需要加一個感嘆號, 但對於登入了後的DDL,DML,則直接執行SQL語句即可,語句後帶上一個分號,然後回車執行。

 

 

 
  1. The Beeline CLI 支援以下命令列引數:

  2. Option

  3. Description

  4. --autoCommit=[true/false]

  5. Enable/disable automatic transaction commit. Default is false.

  6. Usage: beeline --autoCommit=true

  7. --autosave=[true/false]

  8. Automatically save preferences (true) or do not autosave (false). Default is false.

  9. Usage: beeline --autosave=true

  10. --color=[true/false]

  11. Control whether color is used for display. Default is false.

  12. Usage: beeline --color=true

  13. (Not supported for Separated-Value Output formats. See HIVE-9770)

  14. --delimiterForDSV= DELIMITER

  15. The delimiter for delimiter-separated values output format. Default is '|' character.

  16. Version: 0.14.0 (HIVE-7390)

  17. --fastConnect=[true/false]

  18. When connecting, skip building a list of all tables and columns for tab-completion of

  19. HiveQL statements (true) or build the list (false). Default is true.

  20. Usage: beeline --fastConnect=false

  21. --force=[true/false]

  22. Continue running script even after errors (true) or do not continue (false). Default is false.

  23. Usage: beeline--force=true

  24. --headerInterval=ROWS

  25. The interval for redisplaying column headers, in number of rows, when outputformat is table.

  26. Default is 100.

  27. Usage: beeline --headerInterval=50

  28. (Not supported for Separated-Value Output formats. See HIVE-9770)

  29. --help

  30. Display a usage message.

  31. Usage: beeline --help

  32. --hiveconf property=value

  33. Use value for the given configuration property. Properties that are listed in hive.conf.restricted.list cannot be reset with hiveconf (see Restricted List and Whitelist).

  34. Usage: beeline --hiveconf prop1=value1

  35. Version: 0.13.0 (HIVE-6173)

  36. --hivevar name=value

  37. Hive variable name and value. This is a Hive-specific setting in which variables can be set

  38. at the session level and referenced in Hive commands or queries.

  39. Usage: beeline --hivevar var1=value1

  40. --incremental=[true/false]

  41. Print output incrementally.

  42. --isolation=LEVEL

  43. Set the transaction isolation level to TRANSACTION_READ_COMMITTED

  44. or TRANSACTION_SERIALIZABLE.

  45. See the "Field Detail" section in the Java Connection documentation.

  46. Usage: beeline --isolation=TRANSACTION_SERIALIZABLE

  47. --maxColumnWidth=MAXCOLWIDTH

  48. The maximum column width, in characters, when outputformat is table. Default is 15.

  49. Usage: beeline --maxColumnWidth=25

  50. --maxWidth=MAXWIDTH

  51. The maximum width to display before truncating data, in characters, when outputformat is table.

  52. Default is to query the terminal for current width, then fall back to 80.

  53. Usage: beeline --maxWidth=150

  54. --nullemptystring=[true/false]

  55. Use historic behavior of printing null as empty string (true) or use current behavior of printing

  56. null as NULL (false). Default is false.

  57. Usage: beeline --nullemptystring=false

  58. Version: 0.13.0 (HIVE-4485)

  59. --numberFormat=[pattern]

  60. Format numbers using a DecimalFormat pattern.

  61. Usage: beeline --numberFormat="#,###,##0.00"

  62. --outputformat=[table/vertical/csv/tsv/dsv/csv2/tsv2]

  63. Format mode for result display. Default is table. See Separated-Value Output Formats below for description of recommended sv options.

  64. Usage: beeline --outputformat=tsv

  65. Version: dsv/csv2/tsv2 added in 0.14.0 (HIVE-8615)

  66. --showHeader=[true/false]

  67. Show column names in query results (true) or not (false). Default is true.

  68. Usage: beeline --showHeader=false

  69. --showNestedErrs=[true/false]

  70. Display nested errors. Default is false.

  71. Usage: beeline --showNestedErrs=true

  72. --showWarnings=[true/false]

  73. Display warnings that are reported on the connection after issuing any HiveQL commands.

  74. Default is false.

  75. Usage: beeline --showWarnings=true

  76. --silent=[true/false]

  77. Reduce the amount of informational messages displayed (true) or not (false). It also stops displaying the log messages for the query from HiveServer2 (Hive 0.14 and later). Default is false.

  78. Usage: beeline --silent=true

  79. --truncateTable=[true/false]

  80. If true, truncates table column in the console when it exceeds console length.

  81. Version: 0.14.0 (HIVE-6928)

  82. --verbose=[true/false]

  83. Show verbose error messages and debug information (true) or do not show (false).

  84. Default is false.

  85. Usage: beeline --verbose=true

  86. -d <driver class>

  87. The driver class to use.

  88. Usage: beeline -d driver_class

  89. -e <query>

  90. Query that should be executed. Double or single quotes enclose the query string. This option can be specified multiple times.

  91. Usage: beeline -e "query_string"

  92. Icon

  93. Only a single command per -e option is supported. You can't provide multiple semicolon separated commands. Use the -e option multiple times if you want to achieve this.

  94. Bug fix (null pointer exception): 0.13.0 (HIVE-5765)

  95. Bug to be fixed (running -e in background): workaround available (HIVE-6758)

  96. Bug fix (--headerInterval not honored): 0.14.0 (HIVE-7647)

  97. -f <file>

  98. Script file that should be executed.

  99. Usage: beeline -f filepath

  100. Version: 0.12.0 (HIVE-4268)

  101. Note: If the script contains tabs, query compilation fails in version 0.12.0. This bug is fixed in version 0.13.0 (HIVE-6359).

  102. Bug to be fixed (running -f in background): workaround available (HIVE-6758)

  103. -n <username>

  104. The username to connect as.

  105. Usage: beeline -n valid_user

  106. -p <password>

  107. The password to connect as.

  108. Usage: beeline -p valid_password

  109. -u <database URL>

  110. The JDBC URL to connect to.

  111. Usage: beeline -u db_URL