为了提高写HiveSQL的体验,这里通过Qwen3Coder生成了一个vscode的snippets.
欢迎体验:
关于如何创建,修改snippets,可以搜索下
json
{
"Hive Create Table": {
"prefix": "hive_create",
"body": [
"CREATE TABLE IF NOT EXISTS ${1:table_name} (",
"\t${2:column1} ${3:string},",
"\t${4:column2} ${5:int}",
")",
"COMMENT '${6:Table description}'",
"ROW FORMAT DELIMITED",
"FIELDS TERMINATED BY '${7:\\t}'",
"LINES TERMINATED BY '${8:\\n}'",
"STORED AS ${9:TEXTFILE};"
],
"description": "创建Hive表基础模板"
},
"Hive Create Table with Partition": {
"prefix": "hive_create_partition",
"body": [
"CREATE TABLE IF NOT EXISTS ${1:table_name} (",
"\t${2:column1} ${3:string},",
"\t${4:column2} ${5:int}",
")",
"COMMENT '${6:Table description}'",
"PARTITIONED BY (${7:partition_col} ${8:string})",
"ROW FORMAT DELIMITED",
"FIELDS TERMINATED BY '${9:\\t}'",
"STORED AS ${10:TEXTFILE};"
],
"description": "创建带分区的Hive表"
},
"Hive Create External Table": {
"prefix": "hive_create_external",
"body": [
"CREATE EXTERNAL TABLE IF NOT EXISTS ${1:table_name} (",
"\t${2:column1} ${3:string},",
"\t${4:column2} ${5:int}",
")",
"COMMENT '${6:Table description}'",
"LOCATION '${7:/path/to/data}';"
],
"description": "创建外部表"
},
"Hive Drop Table": {
"prefix": "hive_drop",
"body": [
"DROP TABLE IF EXISTS ${1:table_name};"
],
"description": "删除Hive表"
},
"Hive Drop Database": {
"prefix": "hive_drop_db",
"body": [
"DROP DATABASE IF EXISTS ${1:database_name} CASCADE;"
],
"description": "删除Hive数据库"
},
"Hive Select Basic": {
"prefix": "hive_select",
"body": [
"SELECT ${1:*} FROM ${2:table_name}${3: LIMIT 10};"
],
"description": "基本SELECT查询"
},
"Hive Select with Where": {
"prefix": "hive_select_where",
"body": [
"SELECT ${1:column1, column2}",
"FROM ${2:table_name}",
"WHERE ${3:condition};"
],
"description": "带WHERE条件的SELECT查询"
},
"Hive Select with Group By": {
"prefix": "hive_select_group",
"body": [
"SELECT ${1:group_column}, COUNT(*) as count",
"FROM ${2:table_name}",
"GROUP BY ${3:group_column}",
"ORDER BY ${4:count DESC};"
],
"description": "带GROUP BY的SELECT查询"
},
"Hive Insert Overwrite": {
"prefix": "hive_insert_overwrite",
"body": [
"INSERT OVERWRITE TABLE ${1:target_table}",
"SELECT ${2:*} FROM ${3:source_table}${4: WHERE condition};"
],
"description": "覆盖插入数据"
},
"Hive Insert Into": {
"prefix": "hive_insert_into",
"body": [
"INSERT INTO TABLE ${1:target_table}",
"SELECT ${2:*} FROM ${3:source_table}${4: WHERE condition};"
],
"description": "追加插入数据"
},
"Hive Load Data": {
"prefix": "hive_load",
"body": [
"LOAD DATA ${1:LOCAL} INPATH '${2:/path/to/file}'",
"${3:OVERWRITE} INTO TABLE ${4:table_name}${5: PARTITION (partition_col='value')};"
],
"description": "加载数据到表中"
},
"Hive Alter Table Add Column": {
"prefix": "hive_alter_add",
"body": [
"ALTER TABLE ${1:table_name} ADD COLUMNS (${2:column_name} ${3:string} COMMENT '${4:comment}');"
],
"description": "添加列到表中"
},
"Hive Alter Table Rename": {
"prefix": "hive_alter_rename",
"body": [
"ALTER TABLE ${1:old_table_name} RENAME TO ${2:new_table_name};"
],
"description": "重命名表"
},
"Hive Show Tables": {
"prefix": "hive_show_tables",
"body": [
"SHOW TABLES${1: LIKE '${2:pattern}'};"
],
"description": "显示表列表"
},
"Hive Describe Table": {
"prefix": "hive_desc",
"body": [
"DESCRIBE ${1:table_name};"
],
"description": "描述表结构"
},
"Hive Describe Extended": {
"prefix": "hive_desc_ext",
"body": [
"DESCRIBE EXTENDED ${1:table_name};"
],
"description": "详细描述表信息"
},
"Hive String Functions": {
"prefix": "hive_string_funcs",
"body": [
"-- 字符串函数示例",
"SELECT ",
"\tconcat(${1:col1}, ${2:col2}) as concatenated,",
"\tupper(${3:col}) as upper_case,",
"\tlower(${4:col}) as lower_case,",
"\tlength(${5:col}) as str_length,",
"\tsubstring(${6:col}, ${7:start_pos}, ${8:length}) as substr,",
"\tsplit(${9:col}, '${10:delimiter}') as split_array",
"FROM ${11:table_name};"
],
"description": "常用字符串函数"
},
"Hive Date Functions": {
"prefix": "hive_date_funcs",
"body": [
"-- 日期函数示例",
"SELECT ",
"\tcurrent_date() as today,",
"\tcurrent_timestamp() as now,",
"\tdate_add(${1:date_col}, ${2:days}) as date_plus,",
"\tdate_sub(${3:date_col}, ${4:days}) as date_minus,",
"\tdatediff(${5:date1}, ${6:date2}) as date_diff,",
"\tyear(${7:date_col}) as year_part,",
"\tmonth(${8:date_col}) as month_part,",
"\tday(${9:date_col}) as day_part",
"FROM ${10:table_name};"
],
"description": "常用日期函数"
},
"Hive Math Functions": {
"prefix": "hive_math_funcs",
"body": [
"-- 数学函数示例",
"SELECT ",
"\tround(${1:col}, ${2:decimal_places}) as rounded,",
"\tceil(${3:col}) as ceiling,",
"\tfloor(${4:col}) as floor_value,",
"\tabs(${5:col}) as absolute,",
"\tsqrt(${6:col}) as square_root,",
"\tpower(${7:col}, ${8:exponent}) as power_value",
"FROM ${9:table_name};"
],
"description": "常用数学函数"
},
"Hive Aggregate Functions": {
"prefix": "hive_agg_funcs",
"body": [
"-- 聚合函数示例",
"SELECT ",
"\tcount(${1:*}) as total_count,",
"\tcount(distinct ${2:col}) as distinct_count,",
"\tsum(${3:col}) as sum_value,",
"\tavg(${4:col}) as average_value,",
"\tmin(${5:col}) as min_value,",
"\tmax(${6:col}) as max_value",
"FROM ${7:table_name}",
"GROUP BY ${8:group_column};"
],
"description": "常用聚合函数"
},
"Hive Window Functions": {
"prefix": "hive_window_funcs",
"body": [
"-- 窗口函数示例",
"SELECT ",
"\t${1:col},",
"\trow_number() OVER (PARTITION BY ${2:partition_col} ORDER BY ${3:order_col}) as row_num,",
"\trank() OVER (PARTITION BY ${4:partition_col} ORDER BY ${5:order_col}) as rank_val,",
"\tdense_rank() OVER (PARTITION BY ${6:partition_col} ORDER BY ${7:order_col}) as dense_rank_val,",
"\tlead(${8:col}, 1) OVER (PARTITION BY ${9:partition_col} ORDER BY ${10:order_col}) as next_val,",
"\tlag(${11:col}, 1) OVER (PARTITION BY ${12:partition_col} ORDER BY ${13:order_col}) as prev_val",
"FROM ${14:table_name};"
],
"description": "常用窗口函数"
},
"Hive Join Operations": {
"prefix": "hive_join",
"body": [
"SELECT ${1:t1.col1, t2.col2}",
"FROM ${2:table1} t1",
"${3:INNER JOIN} ${4:table2} t2 ON t1.${5:join_key} = t2.${6:join_key}",
"${7:WHERE condition};"
],
"description": "JOIN操作"
},
"Hive Left Join": {
"prefix": "hive_left_join",
"body": [
"SELECT ${1:t1.col1, t2.col2}",
"FROM ${2:table1} t1",
"LEFT JOIN ${3:table2} t2 ON t1.${4:join_key} = t2.${5:join_key}",
"${6:WHERE condition};"
],
"description": "LEFT JOIN操作"
},
"Hive Case When": {
"prefix": "hive_case",
"body": [
"CASE ",
"\tWHEN ${1:condition1} THEN '${2:value1}'",
"\tWHEN ${3:condition2} THEN '${4:value2}'",
"\tELSE '${5:default_value}'",
"END AS ${6:new_column}"
],
"description": "CASE WHEN条件语句"
},
"Hive Multi-line Comment": {
"prefix": "hive_comment_multi",
"body": [
"/*",
" * ${1:Multi-line comment}",
" * ${2:Add more comments here}",
" */"
],
"description": "多行注释"
},
"Hive Single-line Comment": {
"prefix": "hive_comment_single",
"body": [
"-- ${1:Single line comment}"
],
"description": "单行注释"
},
"Hive CTE (Common Table Expression)": {
"prefix": "hive_cte",
"body": [
"WITH ${1:cte_name} AS (",
"\tSELECT ${2:*}",
"\tFROM ${3:table_name}",
"\tWHERE ${4:condition}",
")",
"SELECT ${5:*} FROM ${6:cte_name}${7: WHERE condition};"
],
"description": "公用表表达式(CTE)"
},
"Hive Create Database": {
"prefix": "hive_create_db",
"body": [
"CREATE DATABASE IF NOT EXISTS ${1:database_name}",
"COMMENT '${2:Database description}'",
"LOCATION '${3:/path/to/database}';"
],
"description": "创建数据库"
},
"Hive Use Database": {
"prefix": "hive_use_db",
"body": [
"USE ${1:database_name};"
],
"description": "切换数据库"
},
"Hive Show Databases": {
"prefix": "hive_show_dbs",
"body": [
"SHOW DATABASES;"
],
"description": "显示数据库列表"
},
"Hive Set Properties": {
"prefix": "hive_set",
"body": [
"SET ${1:property_name}=${2:property_value};"
],
"description": "设置Hive属性"
},
"Hive Set MapReduce Properties": {
"prefix": "hive_set_mr",
"body": [
"-- MapReduce相关设置",
"SET mapreduce.job.queuename=${1:queue_name};",
"SET mapreduce.job.reduces=${2:reducer_count};",
"SET hive.exec.reducers.bytes.per.reducer=${3:256000000};"
],
"description": "MapReduce属性设置"
}
}