You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ga...@apache.org on 2017/11/02 16:23:04 UTC
[02/12] hive git commit: HIVE-17812 Move remaining classes that
HiveMetaStore depends on. This closes #261. (Alan Gates,
reviewed by Vihang Karajgaonkar)
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAlterTableMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAlterTableMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAlterTableMessage.java
new file mode 100644
index 0000000..ce8c0fa
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONAlterTableMessage.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.AlterTableMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON alter table message
+ */
+public class JSONAlterTableMessage extends AlterTableMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, table, tableType, tableObjBeforeJson, tableObjAfterJson;
+
+ @JsonProperty
+ String isTruncateOp;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, needed for Jackson.
+ */
+ public JSONAlterTableMessage() {
+ }
+
+ public JSONAlterTableMessage(String server, String servicePrincipal, Table tableObjBefore, Table tableObjAfter,
+ boolean isTruncateOp, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = tableObjBefore.getDbName();
+ this.table = tableObjBefore.getTableName();
+ this.tableType = tableObjBefore.getTableType();
+ this.isTruncateOp = Boolean.toString(isTruncateOp);
+ this.timestamp = timestamp;
+ try {
+ this.tableObjBeforeJson = JSONMessageFactory.createTableObjJson(tableObjBefore);
+ this.tableObjAfterJson = JSONMessageFactory.createTableObjJson(tableObjAfter);
+ } catch (TException e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+ checkValid();
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return db;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public String getTableType() {
+ if (tableType != null) return tableType; else return "";
+ }
+
+ @Override
+ public boolean getIsTruncateOp() { return Boolean.parseBoolean(isTruncateOp); }
+
+ @Override
+ public Table getTableObjBefore() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjBeforeJson,Table.class);
+ }
+
+ @Override
+ public Table getTableObjAfter() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjAfterJson,Table.class);
+ }
+
+ public String getTableObjBeforeJson() {
+ return tableObjBeforeJson;
+ }
+
+ public String getTableObjAfterJson() {
+ return tableObjAfterJson ;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateDatabaseMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateDatabaseMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateDatabaseMessage.java
new file mode 100644
index 0000000..f442e99
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateDatabaseMessage.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON Implementation of CreateDatabaseMessage.
+ */
+public class JSONCreateDatabaseMessage extends CreateDatabaseMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONCreateDatabaseMessage() {}
+
+ public JSONCreateDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = db;
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateFunctionMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateFunctionMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateFunctionMessage.java
new file mode 100644
index 0000000..81f5d25
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateFunctionMessage.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON Implementation of CreateFunctionMessage.
+ */
+public class JSONCreateFunctionMessage extends CreateFunctionMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, functionObjJson;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONCreateFunctionMessage() {}
+
+ public JSONCreateFunctionMessage(String server, String servicePrincipal, Function fn, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = fn.getDbName();
+ this.timestamp = timestamp;
+ try {
+ this.functionObjJson = JSONMessageFactory.createFunctionObjJson(fn);
+ } catch (TException ex) {
+ throw new IllegalArgumentException("Could not serialize Function object", ex);
+ }
+ checkValid();
+ }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ public String getFunctionObjJson() {
+ return functionObjJson;
+ }
+
+ @Override
+ public Function getFunctionObj() throws Exception {
+ return (Function) JSONMessageFactory.getTObj(functionObjJson,Function.class);
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateIndexMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateIndexMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateIndexMessage.java
new file mode 100644
index 0000000..a40e524
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateIndexMessage.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Index;
+import org.apache.hadoop.hive.metastore.messaging.CreateIndexMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON Implementation of CreateIndexMessage.
+ */
+public class JSONCreateIndexMessage extends CreateIndexMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, indexObjJson;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONCreateIndexMessage() {}
+
+ public JSONCreateIndexMessage(String server, String servicePrincipal, Index index, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = index.getDbName();
+ try {
+ this.indexObjJson = JSONMessageFactory.createIndexObjJson(index);
+ } catch (TException ex) {
+ throw new IllegalArgumentException("Could not serialize Index object", ex);
+ }
+
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ public String getIndexObjJson() {
+ return indexObjJson;
+ }
+
+ @Override
+ public Index getIndexObj() throws Exception {
+ return (Index) JSONMessageFactory.getTObj(indexObjJson, Index.class);
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java
new file mode 100644
index 0000000..d894af9
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONCreateTableMessage.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.CreateTableMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import com.google.common.collect.Lists;
+
+/**
+ * JSON implementation of CreateTableMessage.
+ */
+public class JSONCreateTableMessage extends CreateTableMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, table, tableType, tableObjJson;
+ @JsonProperty
+ Long timestamp;
+ @JsonProperty
+ List<String> files;
+
+ /**
+ * Default constructor, needed for Jackson.
+ */
+ public JSONCreateTableMessage() {
+ }
+
+ public JSONCreateTableMessage(String server, String servicePrincipal, String db, String table,
+ String tableType, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = db;
+ this.table = table;
+ this.tableType = tableType;
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ public JSONCreateTableMessage(String server, String servicePrincipal, String db, String table,
+ Long timestamp) {
+ this(server, servicePrincipal, db, table, null, timestamp);
+ }
+
+ public JSONCreateTableMessage(String server, String servicePrincipal, Table tableObj,
+ Iterator<String> fileIter, Long timestamp) {
+ this(server, servicePrincipal, tableObj.getDbName(), tableObj.getTableName(),
+ tableObj.getTableType(), timestamp);
+ try {
+ this.tableObjJson = JSONMessageFactory.createTableObjJson(tableObj);
+ } catch (TException e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+ this.files = Lists.newArrayList(fileIter);
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return db;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public String getTableType() {
+ if (tableType != null) return tableType; else return "";
+ }
+
+ @Override
+ public Table getTableObj() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjJson,Table.class);
+ }
+
+ public String getTableObjJson() {
+ return tableObjJson;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+
+ @Override
+ public Iterable<String> getFiles() {
+ return files;
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropConstraintMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropConstraintMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropConstraintMessage.java
new file mode 100644
index 0000000..9e5d582
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropConstraintMessage.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.messaging.DropConstraintMessage;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON implementation of DropConstraintMessage
+ */
+public class JSONDropConstraintMessage extends DropConstraintMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, dbName, tableName, constraintName;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, needed for Jackson.
+ */
+ public JSONDropConstraintMessage() {
+ }
+
+ public JSONDropConstraintMessage(String server, String servicePrincipal, String dbName,
+ String tableName, String constraintName, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.timestamp = timestamp;
+ this.dbName = dbName;
+ this.tableName = tableName;
+ this.constraintName = constraintName;
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return dbName;
+ }
+
+ @Override
+ public String getTable() {
+ return tableName;
+ }
+
+ @Override
+ public String getConstraint() {
+ return constraintName;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java
new file mode 100644
index 0000000..cd8bcdc
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropDatabaseMessage.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON implementation of DropDatabaseMessage.
+ */
+public class JSONDropDatabaseMessage extends DropDatabaseMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONDropDatabaseMessage() {}
+
+ public JSONDropDatabaseMessage(String server, String servicePrincipal, String db, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = db;
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropFunctionMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropFunctionMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropFunctionMessage.java
new file mode 100644
index 0000000..ca32d16
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropFunctionMessage.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.messaging.DropFunctionMessage;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON Implementation of CreateDatabaseMessage.
+ */
+public class JSONDropFunctionMessage extends DropFunctionMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, functionName;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONDropFunctionMessage() {}
+
+ public JSONDropFunctionMessage(String server, String servicePrincipal, Function fn, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = fn.getDbName();
+ this.functionName = fn.getFunctionName();
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+
+ @Override
+ public String getFunctionName() {
+ return functionName;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropIndexMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropIndexMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropIndexMessage.java
new file mode 100644
index 0000000..fb719c2
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropIndexMessage.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Index;
+import org.apache.hadoop.hive.metastore.messaging.DropIndexMessage;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON Implementation of DropIndexMessage.
+ */
+public class JSONDropIndexMessage extends DropIndexMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, indexName, origTableName, indexTableName;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, required for Jackson.
+ */
+ public JSONDropIndexMessage() {}
+
+ public JSONDropIndexMessage(String server, String servicePrincipal, Index index, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = index.getDbName();
+ this.indexName = index.getIndexName();
+ this.origTableName = index.getOrigTableName();
+ this.indexTableName = index.getIndexTableName();
+
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ @Override
+ public String getDB() { return db; }
+
+ @Override
+ public String getServer() { return server; }
+
+ @Override
+ public String getServicePrincipal() { return servicePrincipal; }
+
+ @Override
+ public Long getTimestamp() { return timestamp; }
+
+ @Override
+ public String getIndexName() {
+ return indexName;
+ }
+
+ @Override
+ public String getOrigTableName() {
+ return origTableName;
+ }
+
+ @Override
+ public String getIndexTableName() {
+ return indexTableName;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropPartitionMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropPartitionMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropPartitionMessage.java
new file mode 100644
index 0000000..4689711
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropPartitionMessage.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JSON implementation of DropPartitionMessage.
+ */
+public class JSONDropPartitionMessage extends DropPartitionMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, table, tableType, tableObjJson;
+
+ @JsonProperty
+ Long timestamp;
+
+ @JsonProperty
+ List<Map<String, String>> partitions;
+
+ /**
+ * Default Constructor. Required for Jackson.
+ */
+ public JSONDropPartitionMessage() {
+ }
+
+ public JSONDropPartitionMessage(String server, String servicePrincipal, String db, String table,
+ List<Map<String, String>> partitions, Long timestamp) {
+ this(server, servicePrincipal, db, table, null, partitions, timestamp);
+ }
+
+ public JSONDropPartitionMessage(String server, String servicePrincipal, String db, String table,
+ String tableType, List<Map<String, String>> partitions, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = db;
+ this.table = table;
+ this.tableType = tableType;
+ this.partitions = partitions;
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ public JSONDropPartitionMessage(String server, String servicePrincipal, Table tableObj,
+ List<Map<String, String>> partitionKeyValues, long timestamp) {
+ this(server, servicePrincipal, tableObj.getDbName(), tableObj.getTableName(),
+ tableObj.getTableType(), partitionKeyValues, timestamp);
+ try {
+ this.tableObjJson = JSONMessageFactory.createTableObjJson(tableObj);
+ } catch (TException e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return db;
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public String getTableType() {
+ if (tableType != null) return tableType; else return "";
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public List<Map<String, String>> getPartitions() {
+ return partitions;
+ }
+
+ @Override
+ public Table getTableObj() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjJson, Table.class);
+ }
+
+ public String getTableObjJson() {
+ return tableObjJson;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropTableMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropTableMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropTableMessage.java
new file mode 100644
index 0000000..591c9dd
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONDropTableMessage.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.DropTableMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * JSON implementation of DropTableMessage.
+ */
+public class JSONDropTableMessage extends DropTableMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, table, tableType, tableObjJson;
+
+ @JsonProperty
+ Long timestamp;
+
+ /**
+ * Default constructor, needed for Jackson.
+ */
+ public JSONDropTableMessage() {
+ }
+
+ public JSONDropTableMessage(String server, String servicePrincipal, String db, String table,
+ Long timestamp) {
+ this(server, servicePrincipal, db, table, null, timestamp);
+ }
+
+ public JSONDropTableMessage(String server, String servicePrincipal, String db, String table,
+ String tableType, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+ this.db = db;
+ this.table = table;
+ this.tableType = tableType;
+ this.timestamp = timestamp;
+ checkValid();
+ }
+
+ public JSONDropTableMessage(String server, String servicePrincipal, Table tableObj,
+ Long timestamp) {
+ this(server, servicePrincipal, tableObj.getDbName(), tableObj.getTableName(),
+ tableObj.getTableType(), timestamp);
+ try {
+ this.tableObjJson = JSONMessageFactory.createTableObjJson(tableObj);
+ } catch (TException e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+ checkValid();
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public String getTableType() {
+ if (tableType != null) return tableType; else return "";
+ }
+
+ @Override
+ public Table getTableObj() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjJson,Table.class);
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return db;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONInsertMessage.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONInsertMessage.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONInsertMessage.java
new file mode 100644
index 0000000..39372bd
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONInsertMessage.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.InsertMessage;
+import org.apache.thrift.TException;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import com.google.common.collect.Lists;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * JSON implementation of InsertMessage
+ */
+public class JSONInsertMessage extends InsertMessage {
+
+ @JsonProperty
+ String server, servicePrincipal, db, table, tableType, tableObjJson, ptnObjJson;
+
+ @JsonProperty
+ Long timestamp;
+
+ @JsonProperty
+ String replace;
+
+ @JsonProperty
+ List<String> files;
+
+ /**
+ * Default constructor, needed for Jackson.
+ */
+ public JSONInsertMessage() {
+ }
+
+ public JSONInsertMessage(String server, String servicePrincipal, Table tableObj, Partition ptnObj,
+ boolean replace, Iterator<String> fileIter, Long timestamp) {
+ this.server = server;
+ this.servicePrincipal = servicePrincipal;
+
+ if (null == tableObj) {
+ throw new IllegalArgumentException("Table not valid.");
+ }
+
+ this.db = tableObj.getDbName();
+ this.table = tableObj.getTableName();
+ this.tableType = tableObj.getTableType();
+
+ try {
+ this.tableObjJson = JSONMessageFactory.createTableObjJson(tableObj);
+ if (null != ptnObj) {
+ this.ptnObjJson = JSONMessageFactory.createPartitionObjJson(ptnObj);
+ } else {
+ this.ptnObjJson = null;
+ }
+ } catch (TException e) {
+ throw new IllegalArgumentException("Could not serialize: ", e);
+ }
+
+ this.timestamp = timestamp;
+ this.replace = Boolean.toString(replace);
+ this.files = Lists.newArrayList(fileIter);
+
+ checkValid();
+ }
+
+ @Override
+ public String getTable() {
+ return table;
+ }
+
+ @Override
+ public String getTableType() {
+ if (tableType != null) return tableType; else return "";
+ }
+
+ @Override
+ public String getServer() {
+ return server;
+ }
+
+ @Override
+ public Iterable<String> getFiles() {
+ return files;
+ }
+
+ @Override
+ public String getServicePrincipal() {
+ return servicePrincipal;
+ }
+
+ @Override
+ public String getDB() {
+ return db;
+ }
+
+ @Override
+ public Long getTimestamp() {
+ return timestamp;
+ }
+
+ @Override
+ public boolean isReplace() { return Boolean.parseBoolean(replace); }
+
+ @Override
+ public Table getTableObj() throws Exception {
+ return (Table) JSONMessageFactory.getTObj(tableObjJson,Table.class);
+ }
+
+ @Override
+ public Partition getPtnObj() throws Exception {
+ return ((null == ptnObjJson) ? null : (Partition) JSONMessageFactory.getTObj(ptnObjJson, Partition.class));
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return JSONMessageDeserializer.mapper.writeValueAsString(this);
+ } catch (Exception exception) {
+ throw new IllegalArgumentException("Could not serialize: ", exception);
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageDeserializer.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageDeserializer.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageDeserializer.java
new file mode 100644
index 0000000..15fa4aa
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageDeserializer.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import org.apache.hadoop.hive.metastore.messaging.AddForeignKeyMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddUniqueConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropFunctionMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.InsertMessage;
+import org.apache.hadoop.hive.metastore.messaging.MessageDeserializer;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+/**
+ * MessageDeserializer implementation, for deserializing from JSON strings.
+ */
+public class JSONMessageDeserializer extends MessageDeserializer {
+
+ static ObjectMapper mapper = new ObjectMapper(); // Thread-safe.
+
+ static {
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ mapper.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false);
+ mapper.configure(SerializationConfig.Feature.AUTO_DETECT_IS_GETTERS, false);
+ mapper.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, false);
+ }
+
+ @Override
+ public CreateDatabaseMessage getCreateDatabaseMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONCreateDatabaseMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONCreateDatabaseMessage.", exception);
+ }
+ }
+
+ @Override
+ public DropDatabaseMessage getDropDatabaseMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropDatabaseMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONDropDatabaseMessage.", exception);
+ }
+ }
+
+ @Override
+ public CreateTableMessage getCreateTableMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONCreateTableMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONCreateTableMessage.", exception);
+ }
+ }
+
+ @Override
+ public AlterTableMessage getAlterTableMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAlterTableMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct appropriate alter table type.",
+ exception);
+ }
+ }
+
+ @Override
+ public DropTableMessage getDropTableMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropTableMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONDropTableMessage.", exception);
+ }
+ }
+
+ @Override
+ public AddPartitionMessage getAddPartitionMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAddPartitionMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct AddPartitionMessage.", exception);
+ }
+ }
+
+ @Override
+ public AlterPartitionMessage getAlterPartitionMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAlterPartitionMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct AlterPartitionMessage.", e);
+ }
+ }
+
+ @Override
+ public DropPartitionMessage getDropPartitionMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropPartitionMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct DropPartitionMessage.", exception);
+ }
+ }
+
+ @Override
+ public CreateFunctionMessage getCreateFunctionMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONCreateFunctionMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONCreateFunctionMessage.", exception);
+ }
+ }
+
+ @Override
+ public DropFunctionMessage getDropFunctionMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropFunctionMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONDropDatabaseMessage.", exception);
+ }
+ }
+
+ @Override
+ public CreateIndexMessage getCreateIndexMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONCreateIndexMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONCreateIndexMessage.", exception);
+ }
+ }
+
+ @Override
+ public DropIndexMessage getDropIndexMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropIndexMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONDropIndexMessage.", exception);
+ }
+ }
+
+ @Override
+ public AlterIndexMessage getAlterIndexMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAlterIndexMessage.class);
+ }
+ catch (Exception exception) {
+ throw new IllegalArgumentException("Could not construct JSONAlterIndexMessage.", exception);
+ }
+ }
+
+ @Override
+ public InsertMessage getInsertMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONInsertMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct InsertMessage", e);
+ }
+ }
+
+ @Override
+ public AddPrimaryKeyMessage getAddPrimaryKeyMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAddPrimaryKeyMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct AddPrimaryKeyMessage", e);
+ }
+ }
+
+ @Override
+ public AddForeignKeyMessage getAddForeignKeyMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAddForeignKeyMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct AddForeignKeyMessage", e);
+ }
+ }
+
+ @Override
+ public AddUniqueConstraintMessage getAddUniqueConstraintMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAddUniqueConstraintMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct AddUniqueConstraintMessage", e);
+ }
+ }
+
+ @Override
+ public AddNotNullConstraintMessage getAddNotNullConstraintMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONAddNotNullConstraintMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct AddNotNullConstraintMessage", e);
+ }
+ }
+
+ @Override
+ public DropConstraintMessage getDropConstraintMessage(String messageBody) {
+ try {
+ return mapper.readValue(messageBody, JSONDropConstraintMessage.class);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Could not construct DropConstraintMessage", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageFactory.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageFactory.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageFactory.java
new file mode 100644
index 0000000..916a8e8
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/messaging/json/JSONMessageFactory.java
@@ -0,0 +1,354 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.messaging.json;
+
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+import com.google.common.collect.Iterables;
+
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.Function;
+import org.apache.hadoop.hive.metastore.api.Index;
+import org.apache.hadoop.hive.metastore.api.NotificationEvent;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.SQLForeignKey;
+import org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint;
+import org.apache.hadoop.hive.metastore.api.SQLPrimaryKey;
+import org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.messaging.AddForeignKeyMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddNotNullConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddPrimaryKeyMessage;
+import org.apache.hadoop.hive.metastore.messaging.AddUniqueConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.AlterTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateDatabaseMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateFunctionMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.CreateTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropConstraintMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropDatabaseMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropFunctionMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropIndexMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropPartitionMessage;
+import org.apache.hadoop.hive.metastore.messaging.DropTableMessage;
+import org.apache.hadoop.hive.metastore.messaging.InsertMessage;
+import org.apache.hadoop.hive.metastore.messaging.MessageDeserializer;
+import org.apache.hadoop.hive.metastore.messaging.MessageFactory;
+import org.apache.hadoop.hive.metastore.messaging.PartitionFiles;
+import org.apache.thrift.TBase;
+import org.apache.thrift.TDeserializer;
+import org.apache.thrift.TException;
+import org.apache.thrift.TSerializer;
+import org.apache.thrift.protocol.TJSONProtocol;
+import org.codehaus.jackson.JsonFactory;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+/**
+ * The JSON implementation of the MessageFactory. Constructs JSON implementations of each
+ * message-type.
+ */
+public class JSONMessageFactory extends MessageFactory {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JSONMessageFactory.class.getName());
+
+ private static JSONMessageDeserializer deserializer = new JSONMessageDeserializer();
+
+ @Override
+ public MessageDeserializer getDeserializer() {
+ return deserializer;
+ }
+
+ @Override
+ public String getMessageFormat() {
+ return "json-0.2";
+ }
+
+ @Override
+ public CreateDatabaseMessage buildCreateDatabaseMessage(Database db) {
+ return new JSONCreateDatabaseMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, db.getName(), now());
+ }
+
+ @Override
+ public DropDatabaseMessage buildDropDatabaseMessage(Database db) {
+ return new JSONDropDatabaseMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, db.getName(), now());
+ }
+
+ @Override
+ public CreateTableMessage buildCreateTableMessage(Table table, Iterator<String> fileIter) {
+ return new JSONCreateTableMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, table, fileIter, now());
+ }
+
+ @Override
+ public AlterTableMessage buildAlterTableMessage(Table before, Table after, boolean isTruncateOp) {
+ return new JSONAlterTableMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, before, after, isTruncateOp, now());
+ }
+
+ @Override
+ public DropTableMessage buildDropTableMessage(Table table) {
+ return new JSONDropTableMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, table, now());
+ }
+
+ @Override
+ public AddPartitionMessage buildAddPartitionMessage(Table table,
+ Iterator<Partition> partitionsIterator, Iterator<PartitionFiles> partitionFileIter) {
+ return new JSONAddPartitionMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, table,
+ partitionsIterator, partitionFileIter, now());
+ }
+
+ @Override
+ public AlterPartitionMessage buildAlterPartitionMessage(Table table, Partition before,
+ Partition after, boolean isTruncateOp) {
+ return new JSONAlterPartitionMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, table, before, after, isTruncateOp,
+ now());
+ }
+
+ @Override
+ public DropPartitionMessage buildDropPartitionMessage(Table table,
+ Iterator<Partition> partitionsIterator) {
+ return new JSONDropPartitionMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, table,
+ getPartitionKeyValues(table, partitionsIterator), now());
+ }
+
+ @Override
+ public CreateFunctionMessage buildCreateFunctionMessage(Function fn) {
+ return new JSONCreateFunctionMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, fn, now());
+ }
+
+ @Override
+ public DropFunctionMessage buildDropFunctionMessage(Function fn) {
+ return new JSONDropFunctionMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, fn, now());
+ }
+
+ @Override
+ public CreateIndexMessage buildCreateIndexMessage(Index idx) {
+ return new JSONCreateIndexMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, idx, now());
+ }
+
+ @Override
+ public DropIndexMessage buildDropIndexMessage(Index idx) {
+ return new JSONDropIndexMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, idx, now());
+ }
+
+ @Override
+ public AlterIndexMessage buildAlterIndexMessage(Index before, Index after) {
+ return new JSONAlterIndexMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, before, after, now());
+ }
+
+ @Override
+ public InsertMessage buildInsertMessage(Table tableObj, Partition partObj,
+ boolean replace, Iterator<String> fileIter) {
+ return new JSONInsertMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, tableObj, partObj, replace, fileIter, now());
+ }
+
+ @Override
+ public AddPrimaryKeyMessage buildAddPrimaryKeyMessage(List<SQLPrimaryKey> pks) {
+ return new JSONAddPrimaryKeyMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, pks, now());
+ }
+
+ @Override
+ public AddForeignKeyMessage buildAddForeignKeyMessage(List<SQLForeignKey> fks) {
+ return new JSONAddForeignKeyMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, fks, now());
+ }
+
+ @Override
+ public AddUniqueConstraintMessage buildAddUniqueConstraintMessage(List<SQLUniqueConstraint> uks) {
+ return new JSONAddUniqueConstraintMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, uks, now());
+ }
+
+ @Override
+ public AddNotNullConstraintMessage buildAddNotNullConstraintMessage(List<SQLNotNullConstraint> nns) {
+ return new JSONAddNotNullConstraintMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, nns, now());
+ }
+
+ @Override
+ public DropConstraintMessage buildDropConstraintMessage(String dbName, String tableName,
+ String constraintName) {
+ return new JSONDropConstraintMessage(MS_SERVER_URL, MS_SERVICE_PRINCIPAL, dbName, tableName,
+ constraintName, now());
+ }
+
+ private long now() {
+ return System.currentTimeMillis() / 1000;
+ }
+
+ static Map<String, String> getPartitionKeyValues(Table table, Partition partition) {
+ Map<String, String> partitionKeys = new LinkedHashMap<>();
+ for (int i = 0; i < table.getPartitionKeysSize(); ++i)
+ partitionKeys.put(table.getPartitionKeys().get(i).getName(), partition.getValues().get(i));
+ return partitionKeys;
+ }
+
+ static List<Map<String, String>> getPartitionKeyValues(final Table table,
+ Iterator<Partition> iterator) {
+ return Lists.newArrayList(Iterators.transform(iterator,
+ new com.google.common.base.Function<Partition, Map<String, String>>() {
+ @Override
+ public Map<String, String> apply(@Nullable Partition partition) {
+ return getPartitionKeyValues(table, partition);
+ }
+ }));
+ }
+
+ static String createPrimaryKeyObjJson(SQLPrimaryKey primaryKeyObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(primaryKeyObj, "UTF-8");
+ }
+
+ static String createForeignKeyObjJson(SQLForeignKey foreignKeyObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(foreignKeyObj, "UTF-8");
+ }
+
+ static String createUniqueConstraintObjJson(SQLUniqueConstraint uniqueConstraintObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(uniqueConstraintObj, "UTF-8");
+ }
+
+ static String createNotNullConstraintObjJson(SQLNotNullConstraint notNullConstaintObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(notNullConstaintObj, "UTF-8");
+ }
+
+ static String createTableObjJson(Table tableObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(tableObj, "UTF-8");
+ }
+
+ static String createPartitionObjJson(Partition partitionObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(partitionObj, "UTF-8");
+ }
+
+ static String createFunctionObjJson(Function functionObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(functionObj, "UTF-8");
+ }
+
+ static String createIndexObjJson(Index indexObj) throws TException {
+ TSerializer serializer = new TSerializer(new TJSONProtocol.Factory());
+ return serializer.toString(indexObj, "UTF-8");
+ }
+
+ public static ObjectNode getJsonTree(NotificationEvent event) throws Exception {
+ return getJsonTree(event.getMessage());
+ }
+
+ public static ObjectNode getJsonTree(String eventMessage) throws Exception {
+ JsonParser jsonParser = (new JsonFactory()).createJsonParser(eventMessage);
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(jsonParser, ObjectNode.class);
+ }
+
+ public static Table getTableObj(ObjectNode jsonTree) throws Exception {
+ TDeserializer deSerializer = new TDeserializer(new TJSONProtocol.Factory());
+ Table tableObj = new Table();
+ String tableJson = jsonTree.get("tableObjJson").asText();
+ deSerializer.deserialize(tableObj, tableJson, "UTF-8");
+ return tableObj;
+ }
+
+ /*
+ * TODO: Some thoughts here : We have a current todo to move some of these methods over to
+ * MessageFactory instead of being here, so we can override them, but before we move them over,
+ * we should keep the following in mind:
+ *
+ * a) We should return Iterables, not Lists. That makes sure that we can be memory-safe when
+ * implementing it rather than forcing ourselves down a path wherein returning List is part of
+ * our interface, and then people use .size() or somesuch which makes us need to materialize
+ * the entire list and not change. Also, returning Iterables allows us to do things like
+ * Iterables.transform for some of these.
+ * b) We should not have "magic" names like "tableObjJson", because that breaks expectation of a
+ * couple of things - firstly, that of serialization format, although that is fine for this
+ * JSONMessageFactory, and secondly, that makes us just have a number of mappings, one for each
+ * obj type, and sometimes, as the case is with alter, have multiples. Also, any event-specific
+ * item belongs in that event message / event itself, as opposed to in the factory. It's okay to
+ * have utility accessor methods here that are used by each of the messages to provide accessors.
+ * I'm adding a couple of those here.
+ *
+ */
+
+ public static TBase getTObj(String tSerialized, Class<? extends TBase> objClass) throws Exception{
+ TDeserializer thriftDeSerializer = new TDeserializer(new TJSONProtocol.Factory());
+ TBase obj = objClass.newInstance();
+ thriftDeSerializer.deserialize(obj, tSerialized, "UTF-8");
+ return obj;
+ }
+
+ public static Iterable<? extends TBase> getTObjs(
+ Iterable<String> objRefStrs, final Class<? extends TBase> objClass) throws Exception {
+
+ try {
+ return Iterables.transform(objRefStrs, new com.google.common.base.Function<String,TBase>(){
+ @Override
+ public TBase apply(@Nullable String objStr){
+ try {
+ return getTObj(objStr, objClass);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ } catch (RuntimeException re){
+ // We have to add this bit of exception handling here, because Function.apply does not allow us to throw
+ // the actual exception that might be a checked exception, so we wind up needing to throw a RuntimeException
+ // with the previously thrown exception as its cause. However, since RuntimeException.getCause() returns
+ // a throwable instead of an Exception, we have to account for the possibility that the underlying code
+ // might have thrown a Throwable that we wrapped instead, in which case, continuing to throw the
+ // RuntimeException is the best thing we can do.
+ Throwable t = re.getCause();
+ if (t instanceof Exception){
+ throw (Exception) t;
+ } else {
+ throw re;
+ }
+ }
+ }
+
+ // If we do not need this format of accessor using ObjectNode, this is a candidate for removal as well
+ public static Iterable<? extends TBase> getTObjs(
+ ObjectNode jsonTree, String objRefListName, final Class<? extends TBase> objClass) throws Exception {
+ Iterable<JsonNode> jsonArrayIterator = jsonTree.get(objRefListName);
+ com.google.common.base.Function<JsonNode,String> textExtractor =
+ new com.google.common.base.Function<JsonNode, String>() {
+ @Nullable
+ @Override
+ public String apply(@Nullable JsonNode input) {
+ return input.asText();
+ }
+ };
+ return getTObjs(Iterables.transform(jsonArrayIterator, textExtractor), objClass);
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidCompactionHistoryService.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidCompactionHistoryService.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidCompactionHistoryService.java
new file mode 100644
index 0000000..97bff0e
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidCompactionHistoryService.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.RunnableConfigurable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Purges obsolete items from compaction history data
+ */
+public class AcidCompactionHistoryService implements RunnableConfigurable {
+ private static final Logger LOG = LoggerFactory.getLogger(AcidCompactionHistoryService.class);
+
+ private Configuration conf;
+ private TxnStore txnHandler;
+
+ @Override
+ public void setConf(Configuration configuration) {
+ this.conf = configuration;
+ txnHandler = TxnUtils.getTxnStore(conf);
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+
+ @Override
+ public void run() {
+ TxnStore.MutexAPI.LockHandle handle = null;
+ try {
+ handle = txnHandler.getMutexAPI().acquireLock(TxnStore.MUTEX_KEY.CompactionHistory.name());
+ long startTime = System.currentTimeMillis();
+ txnHandler.purgeCompactionHistory();
+ LOG.debug("History reaper reaper ran for " + (System.currentTimeMillis() - startTime)/1000 +
+ "seconds.");
+ } catch(Throwable t) {
+ LOG.error("Serious error in {}", Thread.currentThread().getName(), ": {}" + t.getMessage(), t);
+ } finally {
+ if(handle != null) {
+ handle.releaseLocks();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidHouseKeeperService.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidHouseKeeperService.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidHouseKeeperService.java
new file mode 100644
index 0000000..7450a2f
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidHouseKeeperService.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.RunnableConfigurable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Performs background tasks for Transaction management in Hive.
+ * Runs inside Hive Metastore Service.
+ */
+public class AcidHouseKeeperService implements RunnableConfigurable {
+ private static final Logger LOG = LoggerFactory.getLogger(AcidHouseKeeperService.class);
+
+ private Configuration conf;
+ private TxnStore txnHandler;
+
+ @Override
+ public void setConf(Configuration configuration) {
+ this.conf = configuration;
+ txnHandler = TxnUtils.getTxnStore(conf);
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+
+ @Override
+ public void run() {
+ TxnStore.MutexAPI.LockHandle handle = null;
+ try {
+ handle = txnHandler.getMutexAPI().acquireLock(TxnStore.MUTEX_KEY.HouseKeeper.name());
+ long startTime = System.currentTimeMillis();
+ txnHandler.performTimeOuts();
+ LOG.debug("timeout reaper ran for " + (System.currentTimeMillis() - startTime)/1000 +
+ "seconds.");
+ } catch(Throwable t) {
+ LOG.error("Serious error in {}", Thread.currentThread().getName(), ": {}" + t.getMessage(), t);
+ } finally {
+ if(handle != null) {
+ handle.releaseLocks();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidWriteSetService.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidWriteSetService.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidWriteSetService.java
new file mode 100644
index 0000000..413fe96
--- /dev/null
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/AcidWriteSetService.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hive.metastore.txn;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.RunnableConfigurable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Periodically cleans WriteSet tracking information used in Transaction management
+ */
+public class AcidWriteSetService implements RunnableConfigurable {
+ private static final Logger LOG = LoggerFactory.getLogger(AcidWriteSetService.class);
+
+ private Configuration conf;
+ private TxnStore txnHandler;
+
+ @Override
+ public void setConf(Configuration configuration) {
+ this.conf = configuration;
+ txnHandler = TxnUtils.getTxnStore(conf);
+ }
+
+ @Override
+ public Configuration getConf() {
+ return conf;
+ }
+
+ @Override
+ public void run() {
+ TxnStore.MutexAPI.LockHandle handle = null;
+ try {
+ handle = txnHandler.getMutexAPI().acquireLock(TxnStore.MUTEX_KEY.WriteSetCleaner.name());
+ long startTime = System.currentTimeMillis();
+ txnHandler.performWriteSetGC();
+ LOG.debug("cleaner ran for " + (System.currentTimeMillis() - startTime)/1000 + "seconds.");
+ } catch(Throwable t) {
+ LOG.error("Serious error in {}", Thread.currentThread().getName(), ": {}" + t.getMessage(), t);
+ } finally {
+ if(handle != null) {
+ handle.releaseLocks();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
index d09c958..756cb4c 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java
@@ -172,6 +172,12 @@ public final class TxnDbUtil {
LOG.error("Error rolling back: " + re.getMessage());
}
+ // Another thread might have already created these tables.
+ if (e.getMessage() != null && e.getMessage().contains("already exists")) {
+ LOG.info("Txn tables already exist, returning");
+ return;
+ }
+
// This might be a deadlock, if so, let's retry
if (e instanceof SQLTransactionRollbackException && deadlockCnt++ < 5) {
LOG.warn("Caught deadlock, retrying db creation");
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java
index da0ee80..2dac899 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/FileUtils.java
@@ -363,4 +363,20 @@ public class FileUtils {
}
return name.toString();
}
+
+ /**
+ * Determine if two objects reference the same file system.
+ * @param fs1 first file system
+ * @param fs2 second file system
+ * @return return true if both file system arguments point to same file system
+ */
+ public static boolean equalsFileSystem(FileSystem fs1, FileSystem fs2) {
+ //When file system cache is disabled, you get different FileSystem objects
+ // for same file system, so '==' can't be used in such cases
+ //FileSystem api doesn't have a .equals() function implemented, so using
+ //the uri for comparison. FileSystem already uses uri+Configuration for
+ //equality in its CACHE .
+ //Once equality has been added in HDFS-9159, we should make use of it
+ return fs1.getUri().equals(fs2.getUri());
+ }
}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java
index c10e36f..ecbddc3 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/HdfsUtils.java
@@ -24,6 +24,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
+import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.client.HdfsAdmin;
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
@@ -44,6 +45,10 @@ import java.util.Map;
public class HdfsUtils {
private static final Logger LOG = LoggerFactory.getLogger(HdfsUtils.class);
private static final String DISTCP_OPTIONS_PREFIX = "distcp.options.";
+ // TODO: this relies on HDFS not changing the format; we assume if we could get inode ID, this
+ // is still going to work. Otherwise, file IDs can be turned off. Later, we should use
+ // as public utility method in HDFS to obtain the inode-based path.
+ private static final String HDFS_ID_PATH_PREFIX = "/.reserved/.inodes/";
/**
* Check the permissions on a file.
@@ -197,4 +202,20 @@ public class HdfsUtils {
return params;
}
+ public static Path getFileIdPath(
+ FileSystem fileSystem, Path path, long fileId) {
+ return (fileSystem instanceof DistributedFileSystem)
+ ? new Path(HDFS_ID_PATH_PREFIX + fileId) : path;
+ }
+
+ public static long getFileId(FileSystem fs, String path) throws IOException {
+ return ensureDfs(fs).getClient().getFileInfo(path).getFileId();
+ }
+
+ private static DistributedFileSystem ensureDfs(FileSystem fs) {
+ if (!(fs instanceof DistributedFileSystem)) {
+ throw new UnsupportedOperationException("Only supported for DFS; got " + fs.getClass());
+ }
+ return (DistributedFileSystem)fs;
+ }
}
http://git-wip-us.apache.org/repos/asf/hive/blob/c5a9673a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java
index 593dee3..b08d9fd 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/utils/JavaUtils.java
@@ -88,6 +88,20 @@ public class JavaUtils {
}
/**
+ * Create an object of the given class using a no-args constructor
+ * @param theClass class to return new object of
+ * @param <T> the type of the class to be returned
+ * @return an object of the requested type
+ */
+ public static <T> T newInstance(Class<T> theClass) {
+ try {
+ return theClass.newInstance();
+ } catch (InstantiationException|IllegalAccessException e) {
+ throw new RuntimeException("Unable to instantiate " + theClass.getName(), e);
+ }
+ }
+
+ /**
* @return name of current host
*/
public static String hostname() {