Improve the operation of the table

This commit is contained in:
baimei 2013-09-16 13:34:43 +08:00
parent 708eea1a9a
commit 8e08798ef7
17 changed files with 335 additions and 196 deletions

View File

@ -23,7 +23,7 @@
padding: 9px 0;
}
</style>
<link href"css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
<link href="css/charisma-app.css" rel="stylesheet">
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
<link href='css/fullcalendar.css' rel='stylesheet'>

View File

@ -7,11 +7,11 @@ $(document).ready(
var id = 'cols_' + num;
$('div#cols_-1').clone(true).attr('id', id).removeAttr(
"style").insertAfter('div#cols');
var id1 = 'div#' + id + ' #cols_name';
var id2 = 'div#' + id + ' #cols_type';
var id3 = 'div#' + id + ' #cols_comment';
$('tr#cols_-1').clone(true).attr('id', id).removeAttr(
"style").insertAfter('table#cols');
var id1 = 'tr#' + id + ' #cols_name';
var id2 = 'tr#' + id + ' #cols_type';
var id3 = 'tr#' + id + ' #cols_comment';
var name1 = 'columns[' + num + '].cols_name';
var name2 = 'columns[' + num + '].cols_type';
var name3 = 'columns[' + num + '].cols_comment';
@ -27,7 +27,7 @@ $(document).ready(
num = num - 1;
if (num >= 1) {
var id = 'div#cols_' + num;
var id = 'tr#cols_' + num;
$(id).remove();
$('p#column_num').text(num);
}
@ -39,11 +39,11 @@ $(document).ready(
var id = 'P_cols_' + num;
$('div#P_cols_-1').clone(true).attr('id', id)
.removeAttr("style").insertAfter('div#P_cols');
var id1 = 'div#' + id + ' #cols_name';
var id2 = 'div#' + id + ' #cols_type';
var id3 = 'div#' + id + ' #cols_comment';
$('tr#P_cols_-1').clone(true).attr('id', id)
.removeAttr("style").insertAfter('table#P_cols');
var id1 = 'tr#' + id + ' #cols_name';
var id2 = 'tr#' + id + ' #cols_type';
var id3 = 'tr#' + id + ' #cols_comment';
var name1 = 'P_columns[' + num + '].cols_name';
var name2 = 'P_columns[' + num + '].cols_type';
@ -60,7 +60,7 @@ $(document).ready(
num = num - 1;
if (num >= 0) {
var id = 'div#P_cols_' + num;
var id = 'tr#P_cols_' + num;
$(id).remove();
$('p#P_column_num').text(num);
}

View File

@ -93,7 +93,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tabledetail?database_name=<s:property value="%{#parameters.database_name}"/>&table_name=<s:property value="%{#parameters.table_name}"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tabledetail?database_name=<s:property value="%{#session.DBname}"/>&table_name=<s:property value="%{#session.TBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>
@ -104,53 +104,63 @@
<fieldset>
<legend></legend>
<s:text name="table name" />
<s:textfield name="table_name" value="%{#parameters.table_name}" readonly="true"/>
<s:textfield name="table_name" value="%{#session.TBname}" readonly="true"/>
<br>
<s:text name="Database name" />
<s:textfield name="database_name"
value="%{#parameters.database_name}" readonly="true" />
value="%{#session.DBname}" readonly="true" />
<br>
</fieldset>
<p>
<fieldset class="form-inline" id="column">
<legend>New Columns</legend>
<div id="cols">
<div align="right" >
<p id="column_num">1</p>
<p id="column_num" style="display:none">1</p>
</div>
<s:text name="Column name" />
<s:textfield id="cols_name" name="columns[0].cols_name" />
<br>
<s:text name="Column type" />
<s:select id="cols_type" list="#{'int':'Int'}"
name="columns[0].cols_type" listKey="key" listValue="value"
headerKey="String" headerValue="String"></s:select>
<s:text name="Column comment" />
<s:textfield id="cols_comment" name="columns[0].cols_comment" />
<br>
<div id="cols_-1" style="display: none">
<s:text name="Column name" />
<s:textfield id="cols_name" />
<br>
<s:text name="Column type" />
<s:select id="cols_type" list="#{'int':'Int'}" listKey="key"
listValue="value" headerKey="String" headerValue="String"></s:select>
<s:text name="Column comment" />
<s:textfield id="cols_comment" />
<br>
</div>
</div>
<table id="cols" >
<tr>
<th><s:text name="Column name" /></th>
<th><s:text name="Column type" /></th>
<th><s:text name="Column comment" /></th>
</tr>
<tr>
<td><s:textfield id="cols_name"
name="columns[0].cols_name" /></td>
<td><s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}"
name="columns[0].cols_type" listKey="key" listValue="value"
headerKey="String" headerValue="String"></s:select></td>
<td><s:textfield id="cols_comment"
name="columns[0].cols_comment" /></td>
</tr>
<tr id="cols_-1" style="display: none" >
<td><s:textfield id="cols_name" /></td>
<td><s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}" listKey="key"
listValue="value" headerKey="String" headerValue="String"></s:select></td>
<td><s:textfield id="cols_comment" /></td>
</tr>
<!-- <tr>
<td></td>
<td></td>
<td></td>
</tr> -->
<input type="button" id="newColumn" value="New Column" >
</table>
<input type="button" id="newColumn" class=" btn btn-small btn-warning" value="New Column" >
<input
type="button" id="removeColumn" value="Remove Column" >
type="button" id="removeColumn" value="Remove Column" class="btn btn-small btn-info" >
</fieldset>
<div class="form-actions">
<button class="btn btn-small btn-success " type="submit"><i class="icon-plus icon-white"></i> Add</button>
<button class="btn">cancel</button>
</div>
</form>

View File

@ -93,7 +93,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tabledetail?database_name=<s:property value="%{#parameters.database_name}"/>&table_name=<s:property value="%{#parameters.table_name}"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tabledetail?database_name=<s:property value="%{#session.DBname}"/>&table_name=<s:property value="%{#session.TBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>
@ -104,12 +104,12 @@
<fieldset>
<legend></legend>
<s:text name="table name" />
<s:textfield name="table_name" value="%{#parameters.table_name}" readonly="true"/>
<s:textfield name="table_name" value="%{#session.TBname}" readonly="true"/>
<br>
<s:text name="Database name" />
<s:textfield name="database_name"
value="%{#parameters.database_name}" readonly="true" />
value="%{#session.DBname}" readonly="true" />
<br>
<s:text name="Column old name" />
<s:textfield id="cols_name" name="col_old_name" value="%{#parameters.col_old_name}" readonly="true"/>
@ -120,7 +120,7 @@
<s:textfield id="cols_name" name="col_new_name" />
<br>
<s:text name="New Column type" />
<s:select id="cols_type" list="#{'int':'Int'}"
<s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}"
name="col_new_type" listKey="key" listValue="value"
headerKey="String" headerValue="String"></s:select>
<s:text name="New Column comment" />
@ -131,7 +131,7 @@
<div class="form-actions">
<button class="btn btn-small btn-primary" type="submit"><i class="icon-ok icon-white"></i>Alter</button>
<button class="btn">cancel</button>
</div>
</form>

View File

@ -95,8 +95,8 @@
<fieldset>
<legend></legend>
<s:text name="Table name:" />
<s:textfield name="table_name" value="%{#parameters.table_name}" readonly="true" />
<div style="display:none"><s:textfield name="database_name" value="%{#parameters.database_name}" readonly="true" /></div>
<s:textfield name="table_name" value="%{#session.TBname}" readonly="true" />
<div style="display:none"><s:textfield name="database_name" value="%{#session.DBname}" readonly="true" /></div>
<br>
<fieldset>
<legend>Clone To</legend>
@ -106,14 +106,14 @@
<s:select list="databaselist" name="to_database_name"
listKey="key" listValue="value"></s:select>
<s:text name="Table new name:" />
<s:textfield name="table_new_name" value="%{#parameters.table_name}" /><s:fielderror><s:param>tablename</s:param></s:fielderror>
<s:textfield name="table_new_name" value="%{#session.TBname}" /><s:fielderror><s:param>tablename</s:param></s:fielderror>
</fieldset>
</fieldset>
<div class="form-actions">
<button class="btn btn-small btn-success" type="submit"><i class="icon-ok icon-white"></i>Clone </button>
<button class="btn">Cancel</button>
</div>
</form>

View File

@ -93,17 +93,18 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#parameters.database_name}"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#session.DBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>
</p>
<form class="span9"
action='<%=request.getContextPath() + "/tableaction/create"%>'>
<fieldset>
<legend>Columns</legend>
<s:text name="table name" />
<s:textfield name="table_name" />
<s:textfield name="table_name" /><%-- <font color="RED"><s:fielderror><s:param>createTableAction</s:param></s:fielderror></font> --%>
<br>
<s:text name="Table type" />
<s:select list="#{'true':'External'}" name="external"
@ -112,7 +113,7 @@
<br>
<s:text name="Database name" />
<s:textfield name="database_name"
value="%{#parameters.database_name}" readonly="true" />
value="%{#session.DBname}" readonly="true" />
<br>
<s:text name="table comment" />
@ -127,59 +128,62 @@
<p>
<fieldset class="form-inline" id="column">
<legend>Fields</legend>
<div id="cols">
<div align="right" style="display:none">
<p id="column_num">1</p>
</div>
<s:text name="Column name" />
<s:textfield id="cols_name" name="columns[0].cols_name" />
<br>
<s:text name="Column type" />
<s:select id="cols_type" list="#{'int':'Int'}"
name="columns[0].cols_type" listKey="key" listValue="value"
headerKey="String" headerValue="String"></s:select>
<s:text name="Column comment" />
<s:textfield id="cols_comment" name="columns[0].cols_comment" />
<br>
<div id="cols_-1" style="display: none">
<s:text name="Column name" />
<s:textfield id="cols_name" />
<br>
<s:text name="Column type" />
<s:select id="cols_type" list="#{'int':'Int'}" listKey="key"
listValue="value" headerKey="String" headerValue="String"></s:select>
<s:text name="Column comment" />
<s:textfield id="cols_comment" />
<br>
</div>
</div>
<table id="cols" >
<tr>
<th><s:text name="Column name" /></th>
<th><s:text name="Column type" /></th>
<th><s:text name="Column comment" /></th>
</tr>
<tr>
<td><s:textfield id="cols_name"
name="columns[0].cols_name" /></td>
<td><s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}"
name="columns[0].cols_type" listKey="key" listValue="value"
headerKey="STRING" headerValue="STRING"></s:select></td>
<td><s:textfield id="cols_comment"
name="columns[0].cols_comment" /></td>
</tr>
<tr id="cols_-1" style="display: none" >
<td><s:textfield id="cols_name" /></td>
<td><s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}" listKey="key"
listValue="value" headerKey="STRING" headerValue="STRING"></s:select></td>
<td><s:textfield id="cols_comment" /></td>
</tr>
</table>
<div align="right"></div> <input type="button" class=" btn btn-small btn-warning"id="newColumn" value="New Column" />
<input type="button" class="btn btn-small btn-info" id="removeColumn" value="Remove Column" />
</fieldset>
<p>
<fieldset class="form-inline">
<legend>Partitioned by</legend>
<div id="P_cols" style="display:none">
<p id="P_column_num" align="left">0</p>
<div id="P_cols_-1" style="display: none">
<s:text name="Column name" />
<s:textfield id="cols_name" />
<br>
<s:text name="Column type" />
<s:select id="cols_type" list="#{'int':'Int'}" listKey="key"
listValue="value" headerKey="String" headerValue="String"></s:select>
<s:text name="Column comment" />
<s:textfield id="cols_comment" />
<br>
<legend>Partitioned by</legend>
<div align="right" style="display:none">
<p id="P_column_num" >0</p>
</div>
</div>
<input type="button" id="newP_Column" class=" btn btn-small btn-warning" value="New Column" /> <input
<table id="P_cols">
<tr>
<th width="220px">Column name</th>
<th width="220px"> Column type</th>
<th width="220px">Column comment</th>
</tr>
<tr id="P_cols_-1" style="display: none">
<td><s:textfield id="cols_name" /></td>
<td><s:select id="cols_type" list="#{'TINYINT':'TINYINT','SMALLINT':'SMALLINT',' INT':'INT','BIGINT':'BIGINT','BOOLEAN':'BOOLEAN','FLOAT':'FLOAT','DOUBLE':'DOUBLE','BINARY':'BINARY','TIMESTAMP':'TIMESTAMP','DECIMAL':'DECIMAL'}" listKey="key"
listValue="value" headerKey="STRING" headerValue="STRING"></s:select>
</td>
<td><s:textfield id="cols_comment" /></td>
</tr>
</table>
<input type="button" id="newP_Column" class=" btn btn-small btn-warning" value="New Column" /> <input
type="button" id="removeP_Column" class="btn btn-small btn-info" value="Remove Column" />
</fieldset>
<p>
@ -200,7 +204,7 @@
<p>
<div class="form-actions">
<button class="btn btn-small btn-primary" type="submit"><i class="icon-ok icon-white"></i>Create </button>
<button class="btn">cancel</button>
</div>
</form>

View File

@ -86,7 +86,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#parameters.database_name}"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#session.DBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>
@ -101,7 +101,7 @@
<div class="form-actions">
<button class="btn btn-primary" type="submit"><i class="icon-ok icon-white"></i>Commit</button>
<button class="btn">Cancel</button>
</div>
</form>

View File

@ -86,7 +86,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="database_name"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name="%{#session.DBname}'>
<i class="icon-arrow-left icon-white"></i>
back
</a>

View File

@ -86,7 +86,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#parameters.database_name}"/>'>
<a class="btn btn-small btn-primary" href='tableaction/tablelist?database_name=<s:property value="%{#session.DBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>

View File

@ -93,12 +93,12 @@
<a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a>
</div>
</div>
<div class="box-content">
<!-- <p class="btn-group">
<button id="table_create" class="btn btn-primary btn-round" onclick="create_table()">create table</button>
</p> -->
<p><a class="btn btn-small btn-primary" href='jsp/createtableform.jsp?database_name=<s:property value="database_name"/>'>
<p><a class="btn btn-small btn-primary" href='jsp/createtableform.jsp?database_name="%{#session.DBname}"'>
<i class="icon-plus icon-white"></i>
Create Table
</a>

View File

@ -93,7 +93,7 @@
<div class="box-content">
<p class="btn-group">
<a class="btn btn-success" href='tableaction/tablelist?database_name=<s:property value="%{#parameters.database_name}"/>'>
<a class="btn btn-success" href='tableaction/tablelist?database_name=<s:property value="%{#session.DBname}"/>'>
<i class="icon-arrow-left icon-white"></i>
back
</a>
@ -108,7 +108,7 @@
<s:text name="Database name" />
<s:textfield name="database_name"
value="%{#parameters.database_name}" readonly="true" />
value="%{#session.DBname}" readonly="true" />
<br>
<s:text name="File path"></s:text>
<s:textfield name="inpath"></s:textfield>
@ -130,28 +130,29 @@
<fieldset class="form-inline">
<legend>Load File into Some Partition of Table </legend>
<div id="P_cols">
<p id="partition_spec_num" align="left">0</p>
<p id="partition_spec_num" align="left" style="display:none">0</p>
<div id="partition_spec_cols_-1" style="display: none">
<s:text name="Column name" />
<s:text name="Partition name" />
<s:textfield id="partition_spec_name" />
<s:text name="Column Value" />
<s:text name="Partition Value" />
<s:textfield id="partition_spec_value" />
<br>
</div>
</div>
<input type="button" id="newpartition_spec" value="Add Partition spec" /> <input
type="button" id="removepartition_spec" value="Remove Partition spec" />
<input type="button" id="newpartition_spec" class=" btn btn-small btn-warning" value="Add Partition spec" /> <input
type="button" id="removepartition_spec" class="btn btn-small btn-info" value="Remove Partition spec" />
</fieldset>
<p>
<div class="form-actions">
<button id="loadfile" class="btn btn-small btn-success" type="submit">Load into table</button>
<button class="btn">Cancel</button>
</div>
</form>

View File

@ -148,7 +148,7 @@
</div>
</div>
<jsp:include page="/jsp/foot.html" />
</div>
<!-- external javascript
================================================== -->

View File

@ -11,13 +11,19 @@ package org.hiveadmin.hive.action;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.hiveadmin.hive.beans.HistoryRecord;
import org.hiveadmin.hive.service.HiveDatabaseService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
/**
@ -30,6 +36,7 @@ import com.opensymphony.xwork2.ActionSupport;
@Scope("session")
public class DatabaseAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String databaseName;
private String description;

View File

@ -11,12 +11,19 @@ package org.hiveadmin.hive.action;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.hiveadmin.hive.beans.Columns;
import org.hiveadmin.hive.service.HiveTableService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.opensymphony.xwork2.ActionSupport;
/**
@ -49,6 +56,7 @@ public class HiveTableAction extends ActionSupport {
* select tag in Strust2
*/
private HashMap<String, String> databaselist;
private HashMap<String, String> partitionlist;
/**
* server:this property is to provide the services for this class
*/
@ -212,7 +220,8 @@ public class HiveTableAction extends ActionSupport {
*/
private List<String> cluster_col_list = new ArrayList<String>();
/**
* dis_col_list:this property is the name of columns that will be used in distributing
* dis_col_list:this property is the name of columns that will be used in
* distributing
*/
private List<String> dis_col_list = new ArrayList<String>();
@ -254,6 +263,17 @@ public class HiveTableAction extends ActionSupport {
* table_data:this property is the list of data from a table
*/
private List<List<String>> table_data;
private String errorMsg = null;
public void keepInfo() {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session = request.getSession();
if (database_name != null)
session.setAttribute("DBname", database_name);
if (table_name != null)
session.setAttribute("TBname", table_name);
}
/**
* createTable is the method to provide the service about creating a table
@ -261,9 +281,17 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String createTable() {
clearErrorsAndMessages();
keepInfo();
table_name = table_name.trim();
System.out.println(table_name + "111111111111");
if (table_name == null || table_name.equals("")) {
log.error("table name is null");
return INPUT;
//addFieldError("createTableAction",getText("table name is null"));
errorMsg = "table name is null";
columns.clear();
P_columns.clear();
return ERROR;
}
try {
@ -273,12 +301,17 @@ public class HiveTableAction extends ActionSupport {
skewed_col_names, skewed_col_values, row_format_value,
file_format, row_sorted_by_cols, hdfs_path,
select_statement, exist_table_or_view_name);
log.info("Sucess to create table!");
// log.info("Sucess to create table!");
columns.clear();
P_columns.clear();
keepInfo();
return SUCCESS;
} catch (Exception e) {
// addFieldError("createTableAction",getText(e.getMessage()));
e.printStackTrace();
log.error(e.getMessage());
errorMsg = e.getMessage();
return ERROR;
}
@ -291,18 +324,15 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String dropTable() {
keepInfo();
if (table_name == null || table_name.equals("")) {
log.error("table name is null");
return INPUT;
}
try {
server.dropTable(table_name, database_name);
log.info("Sucess to drop table");
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -317,17 +347,16 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String truncateTable() {
if (table_name == null || table_name.equals("")) {
log.error("table name is null");
return INPUT;
keepInfo();
}
try {
server.truncateTable(table_name, partition_spec, database_name);
log.info("Success to remove all rows from partition(s)");
return SUCCESS;
} catch (Exception e) {
partition_spec.clear();
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -341,29 +370,33 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String renameTable() {
keepInfo();
boolean result = false;
if (old_name.equals("") || old_name == null) {
log.error("Rename table name error: Old name is null");
result = true;
}
if (new_name.equals("") || new_name == null) {
log.error("Rename table name error: New name is null");
/*
* addFieldError("createTacleAction",
* getText("Rename table name error: New name is null"));
*/
errorMsg = "Rename table name error: New name is null";
result = true;
}
if (result) {
return INPUT;
return ERROR;
}
try {
server.renameTable(old_name, new_name, database_name);
log.info("Success to rename table \"" + old_name + "\"to \""
+ new_name + "\"");
return SUCCESS;
} catch (Exception e) {
/* addFieldError("createTacleAction", getText(e.getMessage())); */
e.printStackTrace();
log.error(e.toString());
errorMsg = e.getMessage();
return ERROR;
}
@ -376,22 +409,22 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String changeColumn() {
keepInfo();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
HttpSession session = request.getSession();
session.setAttribute("OldcolName", col_old_name);
boolean result = false;
if (table_name.equals("") || table_name == null) {
log.error("Change Column error: Table name is null");
result = true;
}
if (col_old_name.equals("") || col_old_name == null) {
log.error("Change Column error: column old name is null");
result = true;
}
if (col_new_name.equals("") || col_new_name == null) {
log.error("Change Column error: Column new name is null");
errorMsg = "Change Column error: Column new name is null";
result = true;
}
if (result) {
return INPUT;
return ERROR;
}
try {
server.changeColumn(table_name, has_column, col_old_name,
@ -401,7 +434,7 @@ public class HiveTableAction extends ActionSupport {
log.info("Success to Change Column ");
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -417,20 +450,23 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String addorReplacecolumn() {
keepInfo();
boolean result = false;
if (table_name.equals("") || table_name == null) {
log.error("Add/replace columnserror: Table name is null");
errorMsg = "Add/replace columnserror: Table name is null";
columns.clear();
result = true;
}
if (columns.isEmpty()) {
log.error("Aadd/replace columnserror:Column new name is null");
result = true;
errorMsg = "Aadd/replace columnserror:Column new name is null";
}
if (result) {
return INPUT;
return ERROR;
}
try {
server.addorReplacecolumn(true, table_name, columns, database_name);
@ -438,7 +474,8 @@ public class HiveTableAction extends ActionSupport {
log.info("Sucess to add/replace columns");
return SUCCESS;
} catch (Exception e) {
columns.clear();
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -453,11 +490,13 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String showTable() {
keepInfo();
try {
tableList = server.showTable(database_name);
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -472,16 +511,18 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String showColumns() {
keepInfo();
if (table_name.equals("") || table_name == null) {
log.error("Show columns error:Table name is null");
return INPUT;
errorMsg = "Show columns error:Table name is null";
return ERROR;
}
try {
columns_name = server.showColumns(tb_in_or_from, table_name,
database_name, db_in_or_from);
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -496,9 +537,11 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String selectFromTable() {
keepInfo();
if (table_name.equals("") || table_name == null) {
log.error("Select from table error:Table name is null");
return INPUT;
errorMsg = "Select from table error:Table name is null";
return ERROR;
}
showColumns();
try {
@ -509,7 +552,7 @@ public class HiveTableAction extends ActionSupport {
database_name);
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -524,28 +567,35 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String loadFileIntoTable() {
keepInfo();
boolean result = false;
if (table_name.equals("") || table_name == null) {
log.error("Load file into table error:Table name is null");
errorMsg = "Load file into table error:Table name is null";
partition_spec.clear();
result = true;
}
if (inpath == null || inpath.equals("")) {
log.error("Load file into table error:REGEX is null");
log.error("Load file into table error:inpath is null");
errorMsg = "Load file into table error:inpath is null";
partition_spec.clear();
result = true;
}
if (result) {
return INPUT;
return ERROR;
}
try {
server.loadFileIntoTable(inpath, overwrite, table_name, local,
partition_spec, database_name);
log.info("Sucess to load file into table");
partition_spec.clear();
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
partition_spec.clear();
return ERROR;
}
@ -558,21 +608,23 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String tableDetails() {
keepInfo();
boolean result = false;
if (table_name.equals("") || table_name == null) {
log.error("Load file into table error:Table name is null");
errorMsg = "Load file into table error:Table name is null";
result = true;
}
if (result) {
return INPUT;
return ERROR;
}
try {
tableDetails = server.describeTable(table_name, database_name);
log.info("Sucess to load file into table");
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -586,14 +638,27 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String cloneTo() {
keepInfo();
try {
databaselist = server.cloneTo();
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}
/* public String getPartition(){
keepInfo();
System.out.print("111111111111111111111111");
try {
partitionlist = server.showPartition(table_name, database_name);
} catch (Exception e) {
e.printStackTrace();
}
return SUCCESS;
}*/
/**
* cloneTable is the method to provide the service: copy an exist table to
* an exist database and rename the table.
@ -601,10 +666,12 @@ public class HiveTableAction extends ActionSupport {
* @return String
*/
public String cloneTable() {
keepInfo();
if (table_new_name.equals("") || table_new_name == null) {
errorMsg = "Load file into table error:Table name is null";
log.error("Load file into table error:Table name is null");
addFieldError("tablename", "table name can't be null");
return INPUT;
// addFieldError("tablename", "table name can't be null");
return ERROR;
}
try {
server.cloneTable(database_name, table_name, to_database_name,
@ -612,7 +679,7 @@ public class HiveTableAction extends ActionSupport {
log.info("Sucess to drop table");
return SUCCESS;
} catch (Exception e) {
errorMsg = e.getMessage();
e.printStackTrace();
log.error(e.toString());
return ERROR;
@ -649,6 +716,14 @@ public class HiveTableAction extends ActionSupport {
return if_not_exists;
}
public HashMap<String, String> getPartitionlist() {
return partitionlist;
}
public void setPartitionlist(HashMap<String, String> partitionlist) {
this.partitionlist = partitionlist;
}
public void setIf_not_exists(boolean if_not_exists) {
this.if_not_exists = if_not_exists;
}
@ -717,6 +792,14 @@ public class HiveTableAction extends ActionSupport {
this.skewed_col_names = skewed_col_names;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public List<String> getSkewed_col_values() {
return skewed_col_values;
}
@ -749,7 +832,6 @@ public class HiveTableAction extends ActionSupport {
this.row_sorted_by_cols = row_sorted_by_cols;
}
public String getHdfs_path() {
return hdfs_path;
}

View File

@ -292,5 +292,7 @@ public interface HiveTableService {
*/
public abstract void cloneTable(String database_name, String table_name,
String to_database_name, String table_new_name) throws Exception;
/* public abstract HashMap<String, String> showPartition(String table_name,String database_name) throws Exception ;
*/
}

View File

@ -177,6 +177,7 @@ public class HiveTableServiceImpl implements HiveTableService {
}
System.out.println("database name:" + database_name);
if (!skewed_col_names.isEmpty()) {
sql = sql + " skewed by (";
Iterator<String> p_entries = skewed_col_names.iterator();
@ -199,6 +200,7 @@ public class HiveTableServiceImpl implements HiveTableService {
sql = sql + " ) ";
}
sql=sql+"ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\t' COLLECTION ITEMS TERMINATED BY '\\s'";
if (!(exist_table_or_view_name == null || exist_table_or_view_name
.equals(""))) {
@ -795,6 +797,7 @@ public class HiveTableServiceImpl implements HiveTableService {
Statement stmt = HiveConnectionBean.getStmt();
stmt.execute("use " + database_name);
System.out.println(sql);
stmt.execute(sql);
stmt.close();
HistoryRecord historyRecord = new HistoryRecord();
@ -808,7 +811,35 @@ public class HiveTableServiceImpl implements HiveTableService {
log.info("Sucess to excute:" + sql);
}
/*@Override
public HashMap<String, String> showPartition(String table_name,String database_name) throws Exception {
String sql = "SHOW PARTITIONS "+ table_name;
Statement stmt = HiveConnectionBean.getStmt();
stmt.execute("use " + database_name);
HashMap<String, String> map = new LinkedHashMap<String, String>();
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
map.put(res.getString(1), res.getString(1));
}
res.close();
stmt.close();
HistoryRecord historyRecord = new HistoryRecord();
historyRecord.setOp_user_name((String) ServletActionContext
.getContext().getSession().get("user"));
historyRecord.setOp_desc(" show partition table:" + table_name
+ " in database:" + database_name);
historyRecord.setOp_res(true);
historyRecord.setOp_sql(sql);
userHistoryLog.addHistotyRecord(historyRecord);
log.info("Sucess to excute:" + sql);
return map;
}
*/
/**
*cloneTo
* @return

View File

@ -1,28 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.allowed.action.names" value="[a-zA-Z0-9._!^-]*" />
<constant name="struts.ui.theme" value="simple"></constant>
<package name="globalpkg" extends="struts-default">
<global-results>
<result name="error">/errorpage.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.NullPointerException">
</exception-mapping>
<exception-mapping result="error" exception="java.lang.NoSuchMethodException">
</exception-mapping>
<exception-mapping result="error" exception="java.lang.Exception">
</exception-mapping>
</global-exception-mappings>
</package>
<package name="globalpkg" extends="struts-default">
<global-results>
<result name="error">/errorpage.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error"
exception="java.lang.NullPointerException">
</exception-mapping>
<exception-mapping result="error"
exception="java.lang.NoSuchMethodException">
</exception-mapping>
<exception-mapping result="error" exception="java.lang.Exception">
</exception-mapping>
</global-exception-mappings>
</package>
<package name="database" extends="globalpkg" namespace="/databaseAction">
<action name="create" class="databaseAction" method="create">
<result name="success" type="redirectAction">getDatabaseList</result>
@ -45,8 +46,7 @@
<result name="error">/errorpage.jsp</result>
</action>
</package>
<package name="hdfsOperation" extends="globalpkg"
namespace="/hdfsOperation">
<package name="hdfsOperation" extends="globalpkg" namespace="/hdfsOperation">
<action name="mkdirs" class="HDFSOperationAction" method="mkdirs">
<result name="success" type="redirectAction">listFileStatus</result>
<result name="error">/errorpage.jsp</result>
@ -87,8 +87,7 @@
<result name="error">/errorpage.jsp</result>
</action>
</package>
<package name="hiveSqlTemplate" extends="globalpkg"
namespace="/hiveSqlTemplate">
<package name="hiveSqlTemplate" extends="globalpkg" namespace="/hiveSqlTemplate">
<action name="createHiveSqlTemplate" class="hiveSqlTemplateAction"
method="createHiveSqlTemplate">
<result name="success" type="redirectAction">fetchHiveSqlTemplateList</result>
@ -150,6 +149,7 @@
<package name="table" extends="globalpkg" namespace="/tableaction">
<action name="tablelist" class="hiveTableAction" method="showTable">
<result name="success">/jsp/tablelist.jsp</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="tabledetail" class="hiveTableAction" method="tableDetails">
@ -158,6 +158,7 @@
</action>
<action name="create" class="hiveTableAction" method="createTable">
<result name="success" type="redirectAction">tablelist</result>
<!-- <result name="input" >/jsp/createtableform.jsp</result> -->
<result name="error">/errorpage.jsp</result>
</action>
<action name="renametable" class="hiveTableAction" method="renameTable">
@ -167,26 +168,27 @@
<action name="droptable" class="hiveTableAction" method="dropTable">
<result name="success" type="redirectAction">tablelist</result>
<result name="error">/errorpage.jsp</result>
</action>
</action>
<action name="truncatetable" class="hiveTableAction" method="truncateTable">
<result name="success" type="redirectAction">tablelist</result>
<result name="error">/errorpage.jsp</result>
<result name="success" type="redirectAction">tablelist</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="loadfileintotable" class="hiveTableAction" method="loadFileIntoTable">
<result name="success" type="redirectAction">showtabledata</result>
<result name="error"> /errorpage.jps</result>
<action name="loadfileintotable" class="hiveTableAction"
method="loadFileIntoTable">
<result name="success" type="redirectAction">showtabledata</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="showtabledata" class="hiveTableAction" method="selectFromTable">
<result name="success" >/jsp/tabledataform.jsp</result>
<result name="error"> /errorpage.jps</result>
<result name="success">/jsp/tabledataform.jsp</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="addcolumns" class="hiveTableAction" method="addorReplacecolumn">
<result name="success" type="redirectAction">tabledetail</result>
<result name="error"> /errorpage.jps</result>
<result name="success" type="redirectAction">tabledetail</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="changecolumns" class="hiveTableAction" method="changeColumn">
<result name="success" type="redirectAction">tabledetail</result>
<result name="error"> /errorpage.jps</result>
<result name="success" type="redirectAction">tabledetail</result>
<result name="error">/errorpage.jsp</result>
</action>
<action name="cloneto" class="hiveTableAction" method="cloneTo">
<result name="success">/jsp/cloneto.jsp</result>
@ -194,7 +196,7 @@
</action>
<action name="clonetable" class="hiveTableAction" method="cloneTable">
<result name="success" type="redirectAction">tablelist</result>
<!-- <result name="input" >/jsp/cloneto.jsp</result> -->
<!-- <result name="input" >/jsp/cloneto.jsp</result> -->
<result name="error">/errorpage.jsp</result>
</action>
</package>