You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemall.apache.org by ta...@apache.org on 2017/10/04 09:28:34 UTC

incubator-hivemall git commit: [HIVEMALL-149] Add tiny script for updating resources/ddl/define-*

Repository: incubator-hivemall
Updated Branches:
  refs/heads/master 7bb5d047d -> d4f4ab9ba


[HIVEMALL-149] Add tiny script for updating resources/ddl/define-*

## What changes were proposed in this pull request?

Add a script for updating resources/ddl/define-*

## What type of PR is it?

Improvement

## What is the Jira issue?

https://issues.apache.org/jira/browse/HIVEMALL-149

## How to use this feature?

`./bin/add_define.sh`

Author: Takuya Kitazawa <k....@gmail.com>

Closes #120 from takuti/HIVEMALL-149-define.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/commit/d4f4ab9b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/tree/d4f4ab9b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hivemall/diff/d4f4ab9b

Branch: refs/heads/master
Commit: d4f4ab9bafec43d29a366bf955e10a62bb9e603d
Parents: 7bb5d04
Author: Takuya Kitazawa <k....@gmail.com>
Authored: Wed Oct 4 18:28:20 2017 +0900
Committer: Takuya Kitazawa <ta...@apache.org>
Committed: Wed Oct 4 18:28:20 2017 +0900

----------------------------------------------------------------------
 README.md          |  6 +++++
 bin/update_ddls.sh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/d4f4ab9b/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 6f0b690..3b62b92 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,12 @@ Contributing
 
 If you are planning to contribute to this repository, we first request you to create an issue at [our JIRA page](https://issues.apache.org/jira/projects/HIVEMALL) even if the topic is not related to source code itself (e.g., documentation, new idea and proposal).
 
+All Hivemall functions are defined under [resources/ddl](resources/ddl). In order to update the definition files, the following script helps inserting function name and class path of your new UDF:
+
+```
+$ ./bin/update_ddls.sh
+```
+
 Note that, before creating a pull request including Java code, please make sure your code follows our coding conventions by applying formatter:
 
 ```

http://git-wip-us.apache.org/repos/asf/incubator-hivemall/blob/d4f4ab9b/bin/update_ddls.sh
----------------------------------------------------------------------
diff --git a/bin/update_ddls.sh b/bin/update_ddls.sh
new file mode 100755
index 0000000..8f64aad
--- /dev/null
+++ b/bin/update_ddls.sh
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# 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.
+#
+
+if [ "$HIVEMALL_HOME" = "" ]; then
+  if [ -e ../bin/${0##*/} ]; then
+    HIVEMALL_HOME=".."
+  elif [ -e ./bin/${0##*/} ]; then
+    HIVEMALL_HOME="."
+  else
+    echo "env HIVEMALL_HOME not defined"
+    exit 1
+  fi
+fi
+
+cd $HIVEMALL_HOME
+
+define_all() {
+  echo "\ndrop temporary function if exists $function_name;\ncreate temporary function $function_name as '$class_path';" >> resources/ddl/define-all.hive
+  echo "Added to resources/ddl/define-all.hive";
+
+  echo "\nsqlContext.sql(\"DROP TEMPORARY FUNCTION IF EXISTS $function_name\")\nsqlContext.sql(\"CREATE TEMPORARY FUNCTION $function_name AS '$class_path'\")" >> resources/ddl/define-all.spark
+  echo "Added to resources/ddl/define-all.spark";
+}
+
+define_all_as_permanent() {
+  echo "\nDROP FUNCTION IF EXISTS $function_name;\nCREATE FUNCTION $function_name as '$class_path' USING JAR '\${hivemall_jar}';" >> resources/ddl/define-all-as-permanent.hive
+  echo "Added to resources/ddl/define-all-as-permanent.hive";
+}
+
+define_additional() {
+  echo "\ndrop temporary function if exists $function_name;\ncreate temporary function $function_name as '$class_path';" >> resources/ddl/define-additional.hive
+  echo "Added to resources/ddl/define-additional.hive";
+}
+
+define_td() {
+  echo "\ncreate temporary function $function_name as '$class_path';" >> resources/ddl/define-udfs.td.hql
+  echo "Added to resources/ddl/define-udfs.td.hql";
+}
+
+read -p "Function name (e.g., 'hivemall_version'): " function_name
+read -p "Class path (e.g., 'hivemall.HivemallVersionUDF'): " class_path
+
+prefix="$(echo "$class_path" | cut -d'.' -f1,2)"
+if [[ $prefix == 'hivemall.xgboost' ]]; then
+  define_all_as_permanent
+  define_additional
+elif [[ $prefix == 'hivemall.nlp' ]]; then
+  define_additional
+  define_td
+else
+  define_all
+  define_all_as_permanent
+  define_td
+fi