hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edwardy...@apache.org
Subject svn commit: r697665 [1/2] - in /incubator/hama/trunk: ./ bin/ conf/ src/java/org/apache/hama/shell/ src/java/org/apache/hama/shell/execution/ src/java/org/apache/hama/shell/parser/ src/java/org/apache/hama/shell/parser/expression/ src/java/org/apache/h...
Date Mon, 22 Sep 2008 06:14:03 GMT
Author: edwardyoon
Date: Sun Sep 21 23:14:03 2008
New Revision: 697665

URL: http://svn.apache.org/viewvc?rev=697665&view=rev
Log:
Hama Shell Implementation

Added:
    incubator/hama/trunk/bin/
    incubator/hama/trunk/bin/hama
    incubator/hama/trunk/bin/hama-config.sh
    incubator/hama/trunk/conf/hama-env.sh
    incubator/hama/trunk/src/java/org/apache/hama/shell/
    incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShell.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellEnv.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellParser.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOpException.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperation.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperator.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/EvalExpression.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaExpression.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaOperation.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/LoadOperation.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/RandMatrixOperation.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/execution/SaveExpression.java
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/grammar
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/script/
    incubator/hama/trunk/src/java/org/apache/hama/shell/parser/script/HamaScriptParser.jj
Modified:
    incubator/hama/trunk/   (props changed)
    incubator/hama/trunk/CHANGES.txt
    incubator/hama/trunk/build.xml

Propchange: incubator/hama/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 21 23:14:03 2008
@@ -2,3 +2,4 @@
 .classpath
 build
 .fbprefs
+src-gen

Modified: incubator/hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/CHANGES.txt?rev=697665&r1=697664&r2=697665&view=diff
==============================================================================
--- incubator/hama/trunk/CHANGES.txt (original)
+++ incubator/hama/trunk/CHANGES.txt Sun Sep 21 23:14:03 2008
@@ -4,6 +4,7 @@
 
   NEW FEATURES
     
+    HAMA-62: Hama Shell Implementation (samuel via edwardyoon)
     HAMA-61: Load / save matrices from HTable (edwardyoon)
     HAMA-51: Add get/setRowAttribute() method (edwardyoon)
     HAMA-13: Matrix multiplication (edwardyoon)

Added: incubator/hama/trunk/bin/hama
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/bin/hama?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/bin/hama (added)
+++ incubator/hama/trunk/bin/hama Sun Sep 21 23:14:03 2008
@@ -0,0 +1,230 @@
+#! /usr/bin/env bash
+#
+#/**
+# * Copyright 2007 The Apache Software Foundation
+# *
+# * 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.
+# */
+# 
+# The hama command script.  Based on the hbase command script putting
+# in hama classes, libs and configurations ahead of hbase's.
+#
+# TODO: Narrow the amount of duplicated code.
+#
+# Environment Variables:
+#
+#   JAVA_HOME        The java implementation to use.  Overrides JAVA_HOME.
+#
+#   HAMA_CLASSPATH   Extra Java CLASSPATH entries.
+#
+#   HAMA_HEAPSIZE    The maximum amount of heap to use, in MB. 
+#                    Default is 1000.
+#
+#   HAMA_CONF_DIR    Alternate conf dir. Default is ${HAMA_HOME}/conf.
+#   
+#   HAMA_JARS        Additional jars to be included for task execution.
+#
+#   HAMA_ROOT_LOGGER The root appender. Default is INFO,console
+#
+bin=`dirname "$0"`
+bin=`cd "$bin"; pwd`
+
+# This will set HAMA_HOME, etc.
+. "$bin"/hama-config.sh
+
+cygwin=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+esac
+
+# if no args specified, show usage
+if [ $# = 0 ]; then
+  echo "Usage: hama <command>"
+  echo "where <command> is one of:"
+  echo "  shell            run the HAMA shell"
+  echo "  examples         run the HAMA examples"
+  echo " or"
+  echo "  CLASSNAME        run the class named CLASSNAME"
+  echo "Most commands print help when invoked w/o parameters."
+  exit 1
+fi
+
+# get arguments
+COMMAND=$1
+shift
+
+# Source the hama-env.sh.  Will have JAVA_HOME defined.
+if [ -f "${HAMA_CONF_DIR}/hama-env.sh" ]; then
+  . "${HAMA_CONF_DIR}/hama-env.sh"
+fi
+
+# some Java parameters
+if [ "$JAVA_HOME" != "" ]; then
+  #echo "run java in $JAVA_HOME"
+  JAVA_HOME=$JAVA_HOME
+fi
+  
+if [ "$JAVA_HOME" = "" ]; then
+  echo "Error: JAVA_HOME is not set."
+  exit 1
+fi
+
+JAVA=$JAVA_HOME/bin/java
+JAVA_HEAP_MAX=-Xmx1000m 
+
+# check envvars which might override default args
+if [ "$HAMA_HEAPSIZE" != "" ]; then
+  #echo "run with heapsize $HAMA_HEAPSIZE"
+  JAVA_HEAP_MAX="-Xmx""$HAMA_HEAPSIZE""m"
+  #echo $JAVA_HEAP_MAX
+fi
+
+# so that filenames w/ spaces are handled correctly in loops below
+IFS=
+
+# CLASSPATH initially contains $HAMA_CONF_DIR
+CLASSPATH="${HAMA_CONF_DIR}"
+
+
+CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
+
+# for developers, add hama classes to CLASSPATH
+if [ -d "$HAMA_HOME/build/classes" ]; then
+  CLASSPATH=${CLASSPATH}:$HAMA_HOME/build/classes
+fi
+if [ -d "$HAMA_HOME/build/test" ]; then
+  CLASSPATH=${CLASSPATH}:$HAMA_HOME/build/test
+fi
+if [ -d "$HAMA_HOME/build/examples" ]; then
+  CLASSPATH=${CLASSPATH}:$HAMA_HOME/build
+fi
+
+# for releases, add hama to CLASSPATH
+for f in $HAMA_HOME/hama*.jar; do
+  if [ -f $f ]; then
+    CLASSPATH=${CLASSPATH}:$f;
+  fi
+  if [[ $f =~ "examples.jar$" ]]; then
+    HAMA_EXAMPLES_JAR=$f;
+  else
+    if [[ $f =~ "test.jar$" ]]; then
+      HAMA_TEST_JAR=$f;
+    else
+      if [[ $f =~ "hama*" ]]; then
+        HAMA_JAR=$f;
+      fi
+    fi
+  fi
+done
+
+# Add libs to CLASSPATH
+for f in $HAMA_HOME/lib/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+  if [[ $f =~ "hbase*" ]]; then
+    if [ "$HAMA_JARS" == "" ] ; then
+      HAMA_JARS=$f;
+    else
+      HAMA_JARS=${HAMA_JARS},$f;
+    fi
+  fi
+done
+
+for f in $HAMA_HOME/lib/jetty-ext/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+for f in $HAMA_HOME/lib/findbugs/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+for f in $HAMA_HOME/lib/findbugs/plugin/*.jar; do
+  CLASSPATH=${CLASSPATH}:$f;
+done
+
+# add user-specified CLASSPATH last
+if [ "$HAMA_CLASSPATH" != "" ]; then
+  CLASSPATH=${CLASSPATH}:${HAMA_CLASSPATH}
+fi
+
+# default log directory & file
+if [ "$HAMA_LOG_DIR" = "" ]; then
+  HAMA_LOG_DIR="$HAMA_HOME/logs"
+fi
+if [ "$HAMA_LOGFILE" = "" ]; then
+  HAMA_LOGFILE='hama.log'
+fi
+
+# cygwin path translation
+if $cygwin; then
+  CLASSPATH=`cygpath -p -w "$CLASSPATH"`
+  HAMA_HOME=`cygpath -d "$HAMA_HOME"`
+  HAMA_LOG_DIR=`cygpath -d "$HAMA_LOG_DIR"`
+fi
+
+# cygwin path translation
+if $cygwin; then
+  JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
+fi
+ 
+# restore ordinary behaviour
+unset IFS
+
+# figure out which class to run
+if [ "$COMMAND" = "shell" ] ; then
+  if [ "$HAMA_JAR" == "" ] ; then
+    echo 'Can not find the hama jar. Please check that if it is in $HAMA_HOME.'
+    exit -1
+  else
+    if [ "$HAMA_JARS" == "" ] ; then
+      echo 'Hama shell to be excuted needs the hbase & hama jar. Please check that if it is in $HAMA_HOME/lib'
+      exit -1
+    else
+      CLASS="org.apache.hadoop.mapred.JobShell -libjars $HAMA_JARS,$HAMA_JAR $HAMA_JAR" 
+    fi
+  fi
+elif [ "$COMMAND" = "examples" ] ; then
+  if [ "$HAMA_EXAMPLES_JAR" == "" ] ; then
+    echo 'Can not find the hama examples jar. Please check that if it is in $HAMA_HOME.'
+    exit -1
+  else
+    if [ "$HAMA_JARS" == "" ] ; then
+      echo 'Hama examples to be excuted needs the hbase & hama jar. Please check that if it is in $HAMA_HOME/lib'
+      exit -1
+    else
+      CLASS="org.apache.hadoop.mapred.JobShell -libjars $HAMA_JARS,$HAMA_JAR $HAMA_EXAMPLES_JAR" 
+    fi
+  fi
+else
+  CLASS=$COMMAND
+fi
+
+# Have JVM dump heap if we run out of memory.  Files will be 'launch directory'
+# and are named like the following: java_pid21612.hprof. Apparently it doesn't
+# 'cost' to have this flag enabled. Its a 1.6 flag only. See:
+# http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better 
+HAMA_OPTS="$HAMA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
+HAMA_OPTS="$HAMA_OPTS -Dhama.log.dir=$HAMA_LOG_DIR"
+HAMA_OPTS="$HAMA_OPTS -Dhama.log.file=$HAMA_LOGFILE"
+HAMA_OPTS="$HAMA_OPTS -Dhama.home.dir=$HAMA_HOME"
+HAMA_OPTS="$HAMA_OPTS -Dhama.id.str=$HAMA_IDENT_STRING"
+HAMA_OPTS="$HAMA_OPTS -Dhama.root.logger=${HAMA_ROOT_LOGGER:-INFO,console}"
+if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
+  HAMA_OPTS="$HAMA_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
+fi  
+
+# run it
+exec "$JAVA" $JAVA_HEAP_MAX $HAMA_OPTS -classpath "$CLASSPATH" $CLASS "$@"

Added: incubator/hama/trunk/bin/hama-config.sh
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/bin/hama-config.sh?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/bin/hama-config.sh (added)
+++ incubator/hama/trunk/bin/hama-config.sh Sun Sep 21 23:14:03 2008
@@ -0,0 +1,65 @@
+#
+#/**
+# * Copyright 2007 The Apache Software Foundation
+# *
+# * 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.
+# */
+
+# included in all the hama scripts with source command
+# should not be executable directly
+# also should not be passed any arguments, since we need original $*
+# Modelled after $HBASE_HOME/bin/hbase-config.sh.
+
+# resolve links - $0 may be a softlink
+
+this="$0"
+while [ -h "$this" ]; do
+  ls=`ls -ld "$this"`
+  link=`expr "$ls" : '.*-> \(.*\)$'`
+  if expr "$link" : '.*/.*' > /dev/null; then
+    this="$link"
+  else
+    this=`dirname "$this"`/"$link"
+  fi
+done
+
+# convert relative path to absolute path
+bin=`dirname "$this"`
+script=`basename "$this"`
+bin=`cd "$bin"; pwd`
+this="$bin/$script"
+
+# the root of the hama installation
+export HAMA_HOME=`dirname "$this"`/..
+
+#check to see if the conf dir or hama home are given as an optional arguments
+while [ $# -gt 1 ]
+do
+  if [ "--config" = "$1" ]
+  then
+    shift
+    confdir=$1
+    shift
+    HAMA_CONF_DIR=$confdir
+  else
+    # Presume we are at end of options and break
+    break
+  fi
+done
+ 
+# Allow alternate hama conf dir location.
+HAMA_CONF_DIR="${HAMA_CONF_DIR:-$HAMA_HOME/conf}"

Modified: incubator/hama/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/build.xml?rev=697665&r1=697664&r2=697665&view=diff
==============================================================================
--- incubator/hama/trunk/build.xml (original)
+++ incubator/hama/trunk/build.xml Sun Sep 21 23:14:03 2008
@@ -1,297 +1,326 @@
-<?xml version="1.0"?>
-
-<!--
-   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.
--->
-
-<project name="hama" default="jar">
-    <property name="version" value="0.1.0-dev" />
-    <property name="Name" value="Hama" />
-    <property name="final.name" value="hama-${version}" />
-    <property name="year" value="2008" />
-
-    <!-- Load all the default properties, and any the user wants    -->
-    <!-- to contribute (without having to type -D or edit this file -->
-    <property file="${user.home}/${name}.build.properties" />
-    <property file="${basedir}/build.properties" />
-
-    <property name="src.dir" location="${basedir}/src/java" />
-    <property name="src.test" location="${basedir}/src/test" />
-    <property name="src.examples" location="${basedir}/src/examples" />
-
-    <property name="lib.dir" value="${basedir}/lib" />
-    <property name="conf.dir" value="${basedir}/conf" />
-    <property name="docs.dir" value="${basedir}/docs" />
-    <property name="docs.src" value="${basedir}/src/docs" />
-
-    <property name="test.output" value="no" />
-    <property name="test.timeout" value="600000" />
-
-    <property name="build.dir" location="${basedir}/build" />
-    <property name="build.lib" location="${build.dir}/lib" />
-    <property name="build.classes" location="${build.dir}/classes" />
-    <property name="build.test" location="${build.dir}/test" />
-    <property name="build.examples" location="${build.dir}/examples" />
-    <property name="build.docs" value="${build.dir}/docs/site" />
-    <property name="build.javadoc" value="${build.docs}/api" />
-    <property name="build.encoding" value="ISO-8859-1" />
-    <property name="build.src" value="${build.dir}/src" />
-    
-    <property name="build.report" value="${build.dir}/reports" />
-    <property name="build.report.findbugs" value="${build.report}/findbugs" />
-    <property name="build.report.tests" value="${build.report}/tests" />
-    
-    <property name="test.build.dir" value="${build.dir}/test" />
-    <property name="test.junit.output.format" value="plain" />
-
-    <property name="dist.dir" value="${build.dir}/${final.name}" />
-
-    <property name="javac.deprecation" value="off" />
-    <property name="javac.debug" value="on" />
-
-    <property name="javadoc.link.java" 
-                 value="http://java.sun.com/javase/6/docs/api/" />
-    <property name="javadoc.packages" value="org.apache.hama.*" />
-
-    <fileset id="lib.jars" dir="${basedir}" includes="lib/*.jar" />
-    <path id="classpath">
-        <fileset refid="lib.jars" />
-        <fileset dir="${lib.dir}/jetty-ext/">
-            <include name="*jar" />
-        </fileset>
-        <fileset dir="${lib.dir}/findbugs/">
-            <include name="*jar" />
-        </fileset>
-        <pathelement location="${build.classes}" />
-        <pathelement location="${conf.dir}" />
-    </path>
-
-    <taskdef name="findbugs" classpathref="classpath" 
-    	classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />
-
-    <target name="init">
-        <mkdir dir="${build.dir}" />
-        <mkdir dir="${build.classes}" />
-        <mkdir dir="${build.test}" />
-        <mkdir dir="${build.examples}" />
-        <mkdir dir="${build.report.findbugs}" />
-        <mkdir dir="${build.report.tests}" />
-        <!--Copy bin, lib, and conf. too-->
-        <mkdir dir="${build.lib}" />
-        <copy todir="${build.lib}">
-            <fileset dir="${lib.dir}" />
-        </copy>
-    </target>
-
-    <target name="compile" depends="init">
-        <!--Compile whats under src and generated java classes made from jsp-->
-        <mkdir dir="${build.src}" />
-        <javac encoding="${build.encoding}" 
-                srcdir="${src.dir};${build.src}" includes="**/*.java" 
-        	destdir="${build.classes}" debug="${javac.debug}" 
-                deprecation="${javac.deprecation}">
-            <classpath refid="classpath" />
-        </javac>
-    </target>
-
-    <target name="compile-examples" depends="compile">
-        <javac encoding="${build.encoding}" srcdir="${src.examples}" 
-                includes="**/*.java" 
-        	destdir="${build.examples}" debug="${javac.debug}" 
-                deprecation="${javac.deprecation}">
-            <classpath refid="classpath" />
-        </javac>
-    </target>
-
-    <!-- Override jar target to specify main class -->
-    <target name="jar" depends="compile">
-        <jar jarfile="${build.dir}/${final.name}.jar" 
-              basedir="${build.classes}">
-        </jar>
-    </target>
-
-    <target name="examples" depends="jar, compile-examples" 
-    	description="Make the hama examples jar.">
-        <jar jarfile="${build.dir}/${final.name}-examples.jar" 
-                basedir="${build.examples}">
-            <manifest>
-                <attribute name="Main-Class" 
-                    value="org/apache/hama/examples/ExampleDriver" />
-            </manifest>
-        </jar>
-    </target>
-
-    <target name="package" depends="jar,javadoc,compile-test, examples" 
-    	description="Build distribution">
-        <mkdir dir="${dist.dir}" />
-        <copy todir="${dist.dir}" includeEmptyDirs="false" flatten="true">
-            <fileset dir="${build.dir}">
-                <include name="${final.name}.jar" />
-                <include name="${final.name}-test.jar" />
-            </fileset>
-        </copy>
-        <mkdir dir="${dist.dir}/lib" />
-        <copy todir="${dist.dir}/lib">
-            <fileset dir="${build.lib}" />
-        </copy>
-        <copy todir="${dist.dir}">
-            <fileset dir=".">
-                <include name="*.txt" />
-            </fileset>
-        </copy>
-        <mkdir dir="${dist.dir}/src" />
-        <copy todir="${dist.dir}/src" includeEmptyDirs="true">
-            <fileset dir="src" excludes="**/*.template **/docs/build/**/*" />
-        </copy>
-    </target>
-
-    <!-- ================================================================== -->
-    <!-- Make release tarball                                               -->
-    <!-- ================================================================== -->
-    <macrodef name="macro_tar" description="Worker Macro for tar">
-        <attribute name="param.destfile" />
-        <element name="param.listofitems" />
-        <sequential>
-            <tar compression="gzip" longfile="gnu" destfile="@{param.destfile}">
-                <param.listofitems />
-            </tar>
-        </sequential>
-    </macrodef>
-    <target name="tar" depends="package" description="Make release tarball">
-        <macro_tar param.destfile="${build.dir}/${final.name}.tar.gz">
-            <param.listofitems>
-                <tarfileset dir="${build.dir}" mode="664">
-                    <exclude name="${final.name}/bin/*" />
-                    <include name="${final.name}/**" />
-                </tarfileset>
-                <tarfileset dir="${build.dir}" mode="755">
-                    <include name="${final.name}/bin/*" />
-                </tarfileset>
-            </param.listofitems>
-        </macro_tar>
-    </target>
-
-    <target name="binary" depends="package" 
-    	description="Make tarball without source and documentation">
-        <macro_tar param.destfile="${build.dir}/${final.name}-bin.tar.gz">
-            <param.listofitems>
-                <tarfileset dir="${build.dir}" mode="664">
-                    <exclude name="${final.name}/bin/*" />
-                    <exclude name="${final.name}/src/**" />
-                    <exclude name="${final.name}/docs/**" />
-                    <include name="${final.name}/**" />
-                </tarfileset>
-                <tarfileset dir="${build.dir}" mode="755">
-                    <include name="${final.name}/bin/*" />
-                </tarfileset>
-            </param.listofitems>
-        </macro_tar>
-    </target>
-
-    <!-- ================================================================== -->
-    <!-- Doc                                                                -->
-    <!-- ================================================================== -->
-    <target name="docs" depends="forrest.check" description="Generate forrest-based documentation. To use, specify -Dforrest.home=&lt;base of Apache Forrest installation&gt; on the command line." if="forrest.home">
-        <exec dir="${docs.src}" executable="${forrest.home}/bin/forrest" 
-               failonerror="true">
-        	<env key="JAVA_HOME" value="${java5.home}"/>
-        </exec>
-        <copy todir="${build.docs}">
-          <fileset dir="${docs.src}/build/site/" />
-        </copy>
-    	<delete dir="${docs.src}/build/"/>
-    </target>
-
-    <target name="forrest.check" unless="forrest.home">
-        <fail message="'forrest.home' is not defined. Please pass -Dforrest.home=&lt;base of Apache Forrest installation&gt; to Ant on the command-line." />
-    </target>
-
-    <!-- Javadoc -->
-    <target name="javadoc" description="Generate javadoc">
-        <mkdir dir="${build.javadoc}" />
-        <javadoc overview="${src.dir}/overview.html" packagenames="org.apache.hama.*" 
-        	    destdir="${build.javadoc}" author="true" version="true" use="true" 
-        	    windowtitle="${Name} ${version} API" doctitle="${Name} ${version} API" 
-        	    bottom="Copyright &amp;copy; ${year} The Apache Software Foundation">
-            <packageset dir="${src.dir}">
-                <include name="org/apache/**" />
-            </packageset>
-            <link href="${javadoc.link.java}" />
-            <classpath>
-                <path refid="classpath" />
-                <pathelement path="${java.class.path}" />
-            </classpath>
-            <group title="${Name}" packages="org.apache.hama.*" />
-        </javadoc>
-    </target>
-
-    <!-- ================================================================== -->
-    <!-- Run unit tests                                                     -->
-    <!-- ================================================================== -->
-    <path id="test.classpath">
-        <pathelement location="${src.test}" />
-        <pathelement location="${build.test}" />
-        <path refid="classpath" />
-        <pathelement location="${build.dir}" />
-    </path>
-
-    <target name="compile-test" depends="compile">
-        <javac encoding="${build.encoding}" srcdir="${src.test}" 
-           includes="**/*.java" destdir="${build.test}" debug="${javac.debug}">
-            <classpath refid="test.classpath" />
-        </javac>
-        <jar jarfile="${build.dir}/${final.name}-test.jar">
-            <fileset dir="${build.test}" includes="org/**" />
-            <fileset dir="${build.classes}" />
-            <fileset dir="${src.test}" includes="**/*.properties" />
-            <manifest>
-              <attribute name="Main-Class" value="org/apache/hama/Benchmarks" />
-            </manifest>
-        </jar>
-    </target>
-
-    <target name="test" depends="compile-test, compile">
-        <junit printsummary="yes" showoutput="${test.output}" haltonfailure="no"
-              fork="yes" maxmemory="512m" errorProperty="tests.failed" 
-        	     failureProperty="tests.failed" timeout="${test.timeout}">
-            <classpath refid="test.classpath" />
-            <formatter type="${test.junit.output.format}" />
-            <batchtest todir="${build.report.tests}">
-                <fileset dir="${src.test}" includes="**/Test*.java" 
-                	 excludes="**/${test.exclude}.java" />
-            </batchtest>
-        </junit>
-        <fail if="tests.failed">Tests failed!</fail>
-    </target>
-
-    <target name="findbugs" depends="init, jar">
-        <findbugs home="${lib.dir}/findbugs" output="xml" 
-        	     outputFile="${build.report.findbugs}/hama-findbugs.xml" 
-        	     auxClasspathRef="classpath">
-            <sourcePath path="${src.dir}" />
-            <class location="${build.dir}/${final.name}.jar" />
-        </findbugs>
-    </target>
-    
-    <target name="report" depends="findbugs,test"></target>
-    
-    <!-- ================================================================== -->
-    <!-- Clean.  Delete the build files, and their directories              -->
-    <!-- ================================================================== -->
-    <target name="clean">
-        <delete dir="${build.dir}" />
-    </target>
-</project>
+<?xml version="1.0"?>
+
+<!--
+   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.
+-->
+
+<project name="hama" default="jar">
+    <property name="version" value="0.1.0-dev" />
+    <property name="Name" value="Hama" />
+    <property name="final.name" value="hama-${version}" />
+    <property name="year" value="2008" />
+
+    <!-- Load all the default properties, and any the user wants    -->
+    <!-- to contribute (without having to type -D or edit this file -->
+    <property file="${user.home}/${name}.build.properties" />
+    <property file="${basedir}/build.properties" />
+
+    <property name="src.dir" location="${basedir}/src/java" />
+    <property name="src.gen.dir" location="${basedir}/src-gen" />
+    <property name="src.test" location="${basedir}/src/test" />
+    <property name="src.examples" location="${basedir}/src/examples" />
+
+    <property name="lib.dir" value="${basedir}/lib" />
+    <property name="conf.dir" value="${basedir}/conf" />
+    <property name="docs.dir" value="${basedir}/docs" />
+    <property name="docs.src" value="${basedir}/src/docs" />
+
+	<!-- javacc properties -->
+    <property name="javacc.home" value="${basedir}/lib" />
+
+    <property name="src.gen.parser.expression.dir" value="${src.gen.dir}/org/apache/hama/shell/parser/expression" />
+    <property name="src.gen.parser.script.dir" value="${src.gen.dir}/org/apache/hama/shell/parser/script" />
+
+	<!-- build properties -->
+	
+    <property name="test.output" value="no" />
+    <property name="test.timeout" value="600000" />
+
+    <property name="build.dir" location="${basedir}/build" />
+    <property name="build.lib" location="${build.dir}/lib" />
+    <property name="build.classes" location="${build.dir}/classes" />
+    <property name="build.test" location="${build.dir}/test" />
+    <property name="build.examples" location="${build.dir}/examples" />
+    <property name="build.docs" value="${build.dir}/docs/site" />
+    <property name="build.javadoc" value="${build.docs}/api" />
+    <property name="build.encoding" value="ISO-8859-1" />
+    <property name="build.src" value="${build.dir}/src" />
+    
+    <property name="build.report" value="${build.dir}/reports" />
+    <property name="build.report.findbugs" value="${build.report}/findbugs" />
+    <property name="build.report.tests" value="${build.report}/tests" />
+    
+    <property name="test.build.dir" value="${build.dir}/test" />
+    <property name="test.junit.output.format" value="plain" />
+
+    <property name="dist.dir" value="${build.dir}/${final.name}" />
+
+    <property name="javac.deprecation" value="off" />
+    <property name="javac.debug" value="on" />
+
+    <property name="javadoc.link.java" 
+                 value="http://java.sun.com/javase/6/docs/api/" />
+    <property name="javadoc.packages" value="org.apache.hama.*" />
+
+    <fileset id="lib.jars" dir="${basedir}" includes="lib/*.jar" />
+    <path id="classpath">
+        <fileset refid="lib.jars" />
+        <fileset dir="${lib.dir}/jetty-ext/">
+            <include name="*jar" />
+        </fileset>
+        <fileset dir="${lib.dir}/findbugs/">
+            <include name="*jar" />
+        </fileset>
+        <pathelement location="${build.classes}" />
+        <pathelement location="${conf.dir}" />
+    </path>
+
+    <taskdef name="findbugs" classpathref="classpath" 
+    	classname="edu.umd.cs.findbugs.anttask.FindBugsTask" />
+
+    <target name="init">
+        <mkdir dir="${src.gen.dir}" />
+        <mkdir dir="${src.gen.parser.script.dir}" />
+        <mkdir dir="${src.gen.parser.expression.dir}" />
+        <mkdir dir="${build.dir}" />
+        <mkdir dir="${build.classes}" />
+        <mkdir dir="${build.test}" />
+        <mkdir dir="${build.examples}" />
+        <mkdir dir="${build.report.findbugs}" />
+        <mkdir dir="${build.report.tests}" />
+        <!--Copy bin, lib, and conf. too-->
+        <mkdir dir="${build.lib}" />
+        <copy todir="${build.lib}">
+            <fileset dir="${lib.dir}" />
+        </copy>
+    </target>
+	
+	<!-- ================================================================== -->
+    <!-- Java Compiler Compiler, generate Parsers                           -->
+    <!-- ================================================================== -->
+    <target name="cc-compile" depends="init" description="Create and Compile Parser">
+        <jjtree target="${src.dir}/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt" outputdirectory="${src.gen.parser.expression.dir}" javacchome="${javacc.home}" />
+        <javacc target="${src.gen.parser.expression.dir}/HamaExpressionParser.jj" outputdirectory="${src.gen.parser.expression.dir}" javacchome="${javacc.home}" />
+        <javacc target="${src.dir}/org/apache/hama/shell/parser/script/HamaScriptParser.jj" outputdirectory="${src.gen.parser.script.dir}" javacchome="${javacc.home}" />
+    </target>
+
+    <target name="compile" depends="init, cc-compile">
+        <!--Compile whats under src and generated java classes made from jsp-->
+        <mkdir dir="${build.src}" />
+        <javac encoding="${build.encoding}" 
+                srcdir="${src.dir};${src.gen.dir};${build.src}" includes="**/*.java" 
+        	destdir="${build.classes}" debug="${javac.debug}" 
+                deprecation="${javac.deprecation}">
+            <classpath refid="classpath" />
+        </javac>
+    </target>
+
+    <target name="compile-examples" depends="compile">
+        <javac encoding="${build.encoding}" srcdir="${src.examples}" 
+                includes="**/*.java" 
+        	destdir="${build.examples}" debug="${javac.debug}" 
+                deprecation="${javac.deprecation}">
+            <classpath refid="classpath" />
+        </javac>
+    </target>
+
+    <!-- Override jar target to specify main class -->
+    <target name="jar" depends="compile">
+        <jar jarfile="${build.dir}/${final.name}.jar" 
+              basedir="${build.classes}">
+            <manifest>
+                <attribute name="Main-Class" 
+                    value="org/apache/hama/shell/HamaShell" />
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="examples" depends="jar, compile-examples" 
+    	description="Make the hama examples jar.">
+        <jar jarfile="${build.dir}/${final.name}-examples.jar" 
+                basedir="${build.examples}">
+            <manifest>
+                <attribute name="Main-Class" 
+                    value="org/apache/hama/examples/ExampleDriver" />
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="package" depends="jar,javadoc,compile-test, examples" 
+    	description="Build distribution">
+        <mkdir dir="${dist.dir}" />
+        <copy todir="${dist.dir}" includeEmptyDirs="false" flatten="true">
+            <fileset dir="${build.dir}">
+                <include name="${final.name}.jar" />
+                <include name="${final.name}-test.jar" />
+            </fileset>
+        </copy>
+        <mkdir dir="${dist.dir}/lib" />
+        <copy todir="${dist.dir}/lib">
+            <fileset dir="${build.lib}" />
+        </copy>
+        <copy todir="${dist.dir}">
+            <fileset dir=".">
+                <include name="*.txt" />
+            </fileset>
+        </copy>
+        <mkdir dir="${dist.dir}/src" />
+        <copy todir="${dist.dir}/src" includeEmptyDirs="true">
+            <fileset dir="src" excludes="**/*.template **/docs/build/**/*" />
+        </copy>
+    </target>
+
+    <!-- ================================================================== -->
+    <!-- Make release tarball                                               -->
+    <!-- ================================================================== -->
+    <macrodef name="macro_tar" description="Worker Macro for tar">
+        <attribute name="param.destfile" />
+        <element name="param.listofitems" />
+        <sequential>
+            <tar compression="gzip" longfile="gnu" destfile="@{param.destfile}">
+                <param.listofitems />
+            </tar>
+        </sequential>
+    </macrodef>
+    <target name="tar" depends="package" description="Make release tarball">
+        <macro_tar param.destfile="${build.dir}/${final.name}.tar.gz">
+            <param.listofitems>
+                <tarfileset dir="${build.dir}" mode="664">
+                    <exclude name="${final.name}/bin/*" />
+                    <include name="${final.name}/**" />
+                </tarfileset>
+                <tarfileset dir="${build.dir}" mode="755">
+                    <include name="${final.name}/bin/*" />
+                </tarfileset>
+            </param.listofitems>
+        </macro_tar>
+    </target>
+
+    <target name="binary" depends="package" 
+    	description="Make tarball without source and documentation">
+        <macro_tar param.destfile="${build.dir}/${final.name}-bin.tar.gz">
+            <param.listofitems>
+                <tarfileset dir="${build.dir}" mode="664">
+                    <exclude name="${final.name}/bin/*" />
+                    <exclude name="${final.name}/src/**" />
+                    <exclude name="${final.name}/docs/**" />
+                    <include name="${final.name}/**" />
+                </tarfileset>
+                <tarfileset dir="${build.dir}" mode="755">
+                    <include name="${final.name}/bin/*" />
+                </tarfileset>
+            </param.listofitems>
+        </macro_tar>
+    </target>
+
+    <!-- ================================================================== -->
+    <!-- Doc                                                                -->
+    <!-- ================================================================== -->
+    <target name="docs" depends="forrest.check" description="Generate forrest-based documentation. To use, specify -Dforrest.home=&lt;base of Apache Forrest installation&gt; on the command line." if="forrest.home">
+        <exec dir="${docs.src}" executable="${forrest.home}/bin/forrest" 
+               failonerror="true">
+        	<env key="JAVA_HOME" value="${java5.home}"/>
+        </exec>
+        <copy todir="${build.docs}">
+          <fileset dir="${docs.src}/build/site/" />
+        </copy>
+    	<delete dir="${docs.src}/build/"/>
+    </target>
+
+    <target name="forrest.check" unless="forrest.home">
+        <fail message="'forrest.home' is not defined. Please pass -Dforrest.home=&lt;base of Apache Forrest installation&gt; to Ant on the command-line." />
+    </target>
+
+    <!-- Javadoc -->
+    <target name="javadoc" depends="cc-compile" description="Generate javadoc">
+        <mkdir dir="${build.javadoc}" />
+        <javadoc overview="${src.dir}/overview.html" packagenames="org.apache.hama.*" 
+        	    destdir="${build.javadoc}" author="true" version="true" use="true" 
+        	    windowtitle="${Name} ${version} API" doctitle="${Name} ${version} API" 
+        	    bottom="Copyright &amp;copy; ${year} The Apache Software Foundation">
+            <packageset dir="${src.dir}">
+                <include name="org/apache/**" />
+            </packageset>
+            <packageset dir="${src.gen.dir}">
+                <include name="org/apache/**" />
+            </packageset>
+            <link href="${javadoc.link.java}" />
+            <classpath>
+                <path refid="classpath" />
+                <pathelement path="${java.class.path}" />
+            </classpath>
+            <group title="${Name}" packages="org.apache.hama.*" />
+        </javadoc>
+    </target>
+
+    <!-- ================================================================== -->
+    <!-- Run unit tests                                                     -->
+    <!-- ================================================================== -->
+    <path id="test.classpath">
+        <pathelement location="${src.test}" />
+        <pathelement location="${build.test}" />
+        <path refid="classpath" />
+        <pathelement location="${build.dir}" />
+    </path>
+
+    <target name="compile-test" depends="compile">
+        <javac encoding="${build.encoding}" srcdir="${src.test}" 
+           includes="**/*.java" destdir="${build.test}" debug="${javac.debug}">
+            <classpath refid="test.classpath" />
+        </javac>
+        <jar jarfile="${build.dir}/${final.name}-test.jar">
+            <fileset dir="${build.test}" includes="org/**" />
+            <fileset dir="${build.classes}" />
+            <fileset dir="${src.test}" includes="**/*.properties" />
+            <manifest>
+              <attribute name="Main-Class" value="org/apache/hama/Benchmarks" />
+            </manifest>
+        </jar>
+    </target>
+
+    <target name="test" depends="compile-test, compile">
+        <junit printsummary="yes" showoutput="${test.output}" haltonfailure="no"
+              fork="yes" maxmemory="512m" errorProperty="tests.failed" 
+        	     failureProperty="tests.failed" timeout="${test.timeout}">
+            <classpath refid="test.classpath" />
+            <formatter type="${test.junit.output.format}" />
+            <batchtest todir="${build.report.tests}">
+                <fileset dir="${src.test}" includes="**/Test*.java" 
+                	 excludes="**/${test.exclude}.java" />
+            </batchtest>
+        </junit>
+        <fail if="tests.failed">Tests failed!</fail>
+    </target>
+
+    <target name="findbugs" depends="init, jar">
+        <findbugs home="${lib.dir}/findbugs" output="xml" 
+        	     outputFile="${build.report.findbugs}/hama-findbugs.xml" 
+        	     auxClasspathRef="classpath">
+            <sourcePath path="${src.dir}" />
+            <class location="${build.dir}/${final.name}.jar" />
+        </findbugs>
+    </target>
+    
+    <target name="report" depends="findbugs,test"></target>
+    
+    <!-- ================================================================== -->
+    <!-- Clean.  Delete the build files, and their directories              -->
+    <!-- ================================================================== -->
+    <target name="clean">
+        <delete dir="${src.gen.dir}" />
+        <delete dir="${build.dir}" />
+    </target>
+</project>

Added: incubator/hama/trunk/conf/hama-env.sh
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/conf/hama-env.sh?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/conf/hama-env.sh (added)
+++ incubator/hama/trunk/conf/hama-env.sh Sun Sep 21 23:14:03 2008
@@ -0,0 +1,40 @@
+#
+#/**
+# * Copyright 2007 The Apache Software Foundation
+# *
+# * 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.
+# */
+
+# Set environment variables here.
+
+# The java implementation to use.  Required.
+# export JAVA_HOME=/usr/lib/j2sdk1.5-sun
+
+# hadoop conf dir. to find the mapreduce cluster.
+# export HADOOP_CONF_DIR=
+
+# hbase conf dir. to find the hbase cluster.
+# export HBASE_CONF_DIR= 
+
+# Extra Java CLASSPATH elements.  Optional.
+# export HAMA_CLASSPATH=$HADOOP_CONF_DIR:$HBASE_CONF_DIR
+
+# The maximum amount of heap to use, in MB. Default is 1000.
+# export HBASE_HEAPSIZE=1000
+
+# Where log files are stored.  $HAMA_HOME/logs by default.
+# export HAMA_LOG_DIR=${HAMA_HOME}/logs

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShell.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShell.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShell.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShell.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,91 @@
+/*
+ * 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.hama.shell;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hama.HamaConfiguration;
+
+/**
+ * HamaShell
+ *
+ */
+// TODO : improve to make it executed in batch mode.
+//        now it parse the input stream to expression by expression.
+//        so we only can execute expression by expression.
+//        it is not efficient.
+public class HamaShell {
+
+  private final Log log = LogFactory.getLog(getClass());
+
+  BufferedReader in;
+  HamaShellEnv env;
+  HamaShellParser parser;
+  HamaConfiguration conf;
+
+  /**
+   * HamaShell Constructor.
+   * 
+   * @param in          input stream to be parsed
+   * @param shellEnv    shell environment
+   * @param conf        Hama Configuration
+   */
+  public HamaShell(BufferedReader in, HamaShellEnv shellEnv, HamaConfiguration conf) {
+    this.in = in;
+    this.env = shellEnv;
+    this.conf = conf;
+
+    if (in != null) {
+      parser = new HamaShellParser(in, env, this.conf);
+    }
+  }
+
+  /**
+   * HamaShell Executed in interactive mode.
+   */
+  public void run() {
+    parser.setInteractive(true);
+    parser.parseContOnError();
+  }
+
+  /**
+   * HamaShell Executed in batch mode.
+   */
+  public void exec() {
+    try {
+      parser.setInteractive(false);
+      parser.parseStopOnError();
+    } catch (Exception e) {
+      ByteArrayOutputStream bs = new ByteArrayOutputStream();
+      e.printStackTrace(new PrintStream(bs));
+      log.error(bs.toString());
+      log.error(e.getMessage());
+    }
+  }
+  
+  public static void main(String[] args) {
+    HamaShell shell = new HamaShell(new BufferedReader( new InputStreamReader(System.in)), new HamaShellEnv(), new HamaConfiguration());
+    shell.run();
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellEnv.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellEnv.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellEnv.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellEnv.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.hama.shell;
+
+import java.util.HashMap;
+import java.util.Map;
+/**
+ * HamaShellEnv.
+ * 
+ * Maintain all the aliases in the HamaShell.
+ * 
+ */
+// TODO : 
+//
+// we need other data structures to maintain other informations
+// (such as: operators, common operations, data dependency)
+// so that we can use these information to rearrange the expressions
+// and make the hama shell executed more efficiently and parallel.
+public class HamaShellEnv {
+
+  Map<String, Object> aliases = new HashMap<String, Object>();
+  
+  public Object getAliase(String var) {
+    return aliases.get(var);
+  }
+  
+  public void setAliase(String aliaseName, Object value) {
+    if(aliases.containsKey(aliaseName)) {
+      aliases.remove(aliaseName);
+    }
+    aliases.put(aliaseName, value); 
+  }
+  
+  public boolean containAliase(String aliaseName) {
+    return aliases.containsKey(aliaseName);
+  }
+  
+  public Map<String, Object> getAliases() {
+    return aliases;
+  }
+  
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellParser.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellParser.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellParser.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/HamaShellParser.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,148 @@
+/*
+ * 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.hama.shell;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hama.HamaConfiguration;
+import org.apache.hama.shell.execution.HamaExpression;
+import org.apache.hama.shell.parser.expression.HamaExpressionParser;
+import org.apache.hama.shell.parser.script.HamaScriptParser;
+import org.apache.hama.shell.parser.script.HamaScriptParserTokenManager;
+
+public class HamaShellParser extends HamaScriptParser {
+
+  private final Log log = LogFactory.getLog(getClass());
+
+  // flag to identify that the shell script has been finished.
+  boolean mFinished = false;
+
+  HamaShellEnv shellEnv;
+  HamaConfiguration conf;
+
+  public HamaShellParser(HamaScriptParserTokenManager tm, HamaShellEnv env,
+      HamaConfiguration conf) {
+    super(tm);
+    init(env, conf);
+  }
+
+  public HamaShellParser(InputStream stream, String encoding, HamaShellEnv env,
+      HamaConfiguration conf) {
+    super(stream, encoding);
+    init(env, conf);
+  }
+
+  public HamaShellParser(InputStream stream, HamaShellEnv env,
+      HamaConfiguration conf) {
+    super(stream);
+    init(env, conf);
+  }
+
+  public HamaShellParser(Reader stream, HamaShellEnv env, HamaConfiguration conf) {
+    super(stream);
+    init(env, conf);
+  }
+
+  private void init(HamaShellEnv env, HamaConfiguration conf) {
+    this.shellEnv = env;
+    this.conf = conf;
+  }
+
+  /**
+   * use HamaExpressionParser to parser a hama script expression. such as "a = b +
+   * c;", "a = load 'file' as matrix using 'class' map 4;" ...
+   */
+  @Override
+  protected void processScript(String cmd) throws IOException {
+    if (cmd.charAt(cmd.length() - 1) != ';')
+      cmd = cmd + ";";
+    HamaExpressionParser t = new HamaExpressionParser(new ByteArrayInputStream(
+        cmd.getBytes()), this.shellEnv, this.conf);
+    HamaExpression n;
+    try {
+      n = t.Start();
+      if (n != null)
+        n.execute();
+    } catch (org.apache.hama.shell.parser.expression.ParseException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  protected void printHelp() {
+    System.out.println("Operations:");
+    System.out.println("<hama operation>;");
+    System.out.println("such as : \"A = B + C\" or \"save A as file\"");
+    System.out.println();
+    System.out.println("Commands:");
+    System.out.println("quit -- exit the hama shell");
+    System.out.println("help -- dispaly the usage informations");
+  }
+
+  /**
+   * Display the prompt of hama shell.
+   */
+  @Override
+  public void prompt() {
+    if (mInteractive) {
+      System.out.print("Hama > ");
+      System.out.flush();
+    }
+  }
+
+  @Override
+  protected void quit() {
+    mFinished = true;
+  }
+
+  /**
+   * Used in HamaShell Batch mode.
+   * 
+   * @throws IOException
+   * @throws org.apache.hama.shell.parser.expression.ParseException
+   * @throws org.apache.hama.shell.parser.script.ParseException
+   */
+  public void parseStopOnError() throws IOException,
+      org.apache.hama.shell.parser.expression.ParseException,
+      org.apache.hama.shell.parser.script.ParseException {
+    prompt();
+    mFinished = false;
+    while (!mFinished)
+      parse();
+  }
+
+  /**
+   * Used in HamaShell Interactive mode.
+   */
+  public void parseContOnError() {
+    prompt();
+    mFinished = false;
+    while (!mFinished)
+      try {
+        parse();
+      } catch (Exception e) {
+        log.error(e.toString());
+      }
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOpException.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOpException.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOpException.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOpException.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.hama.shell.execution;
+
+/** exception of algebra operation * */
+public class AlgebraOpException extends Exception {
+
+  /**
+   * 
+   */
+  private static final long serialVersionUID = 1L;
+
+  String description = "AlgebraOpExeption : ";
+
+  public AlgebraOpException() {
+    description += "Please check your expression!";
+  }
+
+  public AlgebraOpException(String why) {
+    description += why;
+  }
+
+  public String toString() {
+    return description;
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperation.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperation.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperation.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperation.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+
+import org.apache.hama.HamaConfiguration;
+
+/**
+ * Algebra Operation.
+ * 
+ * A = (B + C) * (E - F * H) ;
+ * 
+ */
+public class AlgebraOperation extends HamaOperation {
+
+  /**
+   * we store all the algebra operators in
+   * 
+   * @see {@link AlgebraOperation#rootOp}.
+   */
+  AlgebraOperator rootOp;
+
+  public AlgebraOperation(HamaConfiguration conf, AlgebraOperator op) {
+    super(conf);
+    this.rootOp = op;
+  }
+
+  public AlgebraOperation(HamaConfiguration conf, AlgebraOperator op, int map,
+      int reduce) {
+    super(conf, map, reduce);
+    this.rootOp = op;
+  }
+
+  public void setRootOp(AlgebraOperator op) {
+    this.rootOp = op;
+  }
+
+  public Object operate() throws AlgebraOpException, IOException {
+    if (rootOp == null) {
+      System.err
+          .println("AlgebraOperation() rootOp is null. Please Check your expression!");
+      return null;
+    } else {
+      return rootOp.getValue();
+    }
+
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperator.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperator.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperator.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/AlgebraOperator.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,221 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hama.Matrix;
+
+public class AlgebraOperator {
+
+  // to store Matrix, AlgebraOperator.
+  // if *operand* is an AlgebraOperator,
+  // we should call AlgebraOperator.getValue()
+  // to get actual value, then do algebraic operation.
+  Object operand;
+  List<Entry> otherOperands;
+
+  /**
+   * 
+   * An Entry Class to store all the Operators and other Operands.
+   * 
+   */
+  static class Entry {
+    String op;
+    AlgebraOperator operand;
+
+    public Entry(String op, AlgebraOperator operand) {
+      this.op = op;
+      this.operand = operand;
+    }
+
+    public String getOp() {
+      return this.op;
+    }
+
+    public AlgebraOperator getOperand() {
+      return this.operand;
+    }
+  }
+
+  public AlgebraOperator(Object operand) {
+    this.operand = operand;
+    this.otherOperands = null;
+  }
+
+  public void addOpAndOperand(String op, AlgebraOperator otherOperand) {
+    if (otherOperands == null) {
+      this.otherOperands = new ArrayList<Entry>();
+    }
+    this.otherOperands.add(new Entry(op, otherOperand));
+  }
+
+  /**
+   * Do the actual algebra operation here.
+   * 
+   * if it is a
+   * 
+   * @see {@link Matrix} operator, return it's value (matrix). if it is a
+   * @see {@link Matrix#add(Matrix)} operator, do addition and return it's value
+   *      (matrix). if it is a
+   * @see {@link Matrix#mult(Matrix)} operator, do multiplication and return
+   *      it's value (matrix).
+   * 
+   * @return Matrix ( or AlgebraOperator(used internally) )
+   * @throws AlgebraOpException
+   * @throws IOException
+   */
+  public Object getValue() throws AlgebraOpException, IOException {
+    // A Unary Operator.
+    //
+    // A Matrix or A Number, we just return it.
+    //
+    // An AlgebraOperator
+    // we return value through AlgebraOperator.getValue()
+    if (this.otherOperands == null) {
+      if (operand == null)
+        throw new AlgebraOpException("An AlgebraOperator can not be null. "
+            + "Please check the expression.");
+      else {
+        if (this.operand instanceof AlgebraOperator)
+          return ((AlgebraOperator) this.operand).getValue();
+        else
+          return this.operand;
+      }
+    }
+    // An AlgebraOperation.
+    else {
+      if (operand == null)
+        throw new AlgebraOpException("An AlgebraOperator can not be null. "
+            + "Please check the expression.");
+
+      // first, if *operand* is AlgebraOperator,
+      // turn *operand* to value-style(Matrix, Number)
+      if (this.operand instanceof AlgebraOperator)
+        this.operand = ((AlgebraOperator) this.operand).getValue();
+
+      assert this.otherOperands.size() != 0 : "Other operands in an algebra operation should not be zero while [*otherOperands*!=null]";
+
+      // collect all the matrices.
+      List<Matrix> matrices = new ArrayList<Matrix>();
+
+      // we should check the Operator belongs to "+"/"-" or "*".
+
+      // "*"
+
+      if (this.otherOperands.get(0).getOp().equalsIgnoreCase("*")) {
+
+        // we check the operand first.
+        if (this.operand instanceof Matrix) {
+          matrices.add((Matrix) this.operand);
+        } else
+          throw new AlgebraOpException("Uncognized Object Type.");
+
+        // now we loop the otherOperands list.
+        for (Entry entry : this.otherOperands) {
+          Object value = entry.getOperand().getValue();
+
+          if (value instanceof Matrix) {
+            matrices.add((Matrix) value);
+          } else
+            throw new AlgebraOpException("Uncognized Object Type.");
+        }
+
+        // Now do the multiplication.
+        return doListMultiplication(matrices);
+      }
+      // "+"/"-"
+      // 
+      // We only accept the below expression.
+      //
+      // Matrix (+/-) Matrix
+      else {
+        // collect the ops;
+        List<String> ops = new ArrayList<String>();
+        // make sure that all the Matrices have same rows and columns.
+        // for example: A + B + C + D + ... + Z
+        // we will check:
+        // A.rows = B.rows = C.rows = D.rows = ... = Z.rows
+        // A.columns = B.columns = C.columns = D.columns = ... = Z.columns
+        Matrix m = (Matrix) this.operand;
+        int rows = m.getRows();
+        int columns = m.getColumns();
+        for (Entry entry : this.otherOperands) {
+          Object value = entry.getOperand().getValue();
+          String keyOp = entry.getOp();
+
+          if (value instanceof Matrix) {
+            matrices.add((Matrix) value);
+            ops.add(keyOp);
+          } else
+            throw new AlgebraOpException("Uncognized Object Type.");
+
+          if (rows != ((Matrix) value).getRows()
+              && columns != ((Matrix) value).getColumns())
+            throw new AlgebraOpException(
+                "Matrices' rows and columns should be same while A + B + ... + Z. Please check the expression.");
+        }
+
+        m = (Matrix) this.operand;
+        for (int i = 0; i < ops.size(); i++) {
+
+          if (ops.get(i).equalsIgnoreCase("+")) {
+            m = m.add(matrices.get(i));
+          } else if (ops.get(i).equalsIgnoreCase("-")) {
+            m = m.add(-1, matrices.get(i));
+          } else
+            throw new AlgebraOpException(
+                "Uncognized Operator. It should be '+' '-' '*'.");
+
+        }
+
+        return m;
+
+      }
+    } // End of AlgebraOperation.
+
+  }
+
+  private Matrix doListMultiplication(List<Matrix> matrices)
+      throws IOException, AlgebraOpException {
+
+    // do Matrices Multiplication.
+    // First make sure that all the Matrices are suitable for multiplications.
+    // for example: A * B * C * D * ... * Z
+    // we will check A.columns = B.rows, B.columns = C.rows, C.columns = D.rows
+    // ...
+
+    for (int i = 0, j = 1; j < matrices.size(); i++, j++) {
+      if (matrices.get(i).getColumns() != matrices.get(j).getRows())
+        throw new AlgebraOpException(
+            "A's columns should equal with B's rows while A * B. Please check the expression.");
+    }
+
+    // Now we can do multiplication.
+    Matrix matrix = matrices.get(0);
+    for (int i = 1; i < matrices.size(); i++) {
+      Matrix m = matrices.get(i);
+      matrix = matrix.mult(m);
+    }
+
+    return matrix;
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/EvalExpression.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/EvalExpression.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/EvalExpression.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/EvalExpression.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,64 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+
+import org.apache.hama.HamaConfiguration;
+import org.apache.hama.shell.HamaShellEnv;
+
+/**
+ * Eval Expression.
+ * 
+ * Deal with all the evalution expression in hama, like:
+ * 
+ * A = ( LoadOperation | AlgebraOperation )
+ * 
+ */
+public class EvalExpression extends HamaExpression {
+
+  String aliaseName;
+  HamaOperation operation;
+
+  public EvalExpression(HamaConfiguration conf, HamaShellEnv env,
+      String aliase, HamaOperation operation) {
+    super(conf, env);
+    this.aliaseName = aliase;
+    this.operation = operation;
+  }
+
+  @Override
+  public void execute() {
+    try {
+      Object value = operation.operate();
+      if (value == null) {
+        System.err.println("'null' can't be assigned to alias '" + aliaseName
+            + "'");
+      } else {
+        this.env.setAliase(aliaseName, value);
+        System.out.println(aliaseName + " =");
+        System.out.println(value);
+      }
+    } catch (AlgebraOpException e) {
+      e.printStackTrace();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaExpression.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaExpression.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaExpression.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaExpression.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,39 @@
+/*
+ * 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.hama.shell.execution;
+
+import org.apache.hama.HamaConfiguration;
+import org.apache.hama.shell.HamaShellEnv;
+
+/** HamaExpression **/
+abstract public class HamaExpression {
+
+  HamaShellEnv env;
+  HamaConfiguration conf;
+  
+  public HamaExpression(HamaConfiguration conf, HamaShellEnv env) {
+    this.env = env;
+    this.conf = conf;
+  }
+  
+  /**
+   * execute the expression.
+   */
+  abstract public void execute() ;
+  
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaOperation.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaOperation.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaOperation.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/HamaOperation.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,57 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+
+import org.apache.hama.HamaConfiguration;
+
+/** HamaOperation **/
+public abstract class HamaOperation {
+
+  HamaConfiguration conf;
+  int map, reduce;
+  
+  public HamaOperation(HamaConfiguration conf) {
+    this(conf, 2, 1);
+  }
+  
+  public HamaOperation(HamaConfiguration conf, int map, int reduce) {
+    this.conf = conf;
+    this.map = map;
+    this.reduce = reduce;
+  }
+  
+  public void setMapNum(int mapNum) {
+    this.map = mapNum;
+  }
+  
+  public void setReduceNum(int reduceNum) {
+    this.reduce = reduceNum;
+  }
+  
+  /**
+   * do the operation.
+   * 
+   * @return Matrix
+   * @throws AlgebraOpException
+   * @throws IOException
+   */
+  abstract public Object operate() throws AlgebraOpException, IOException ;
+  
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/LoadOperation.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/LoadOperation.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/LoadOperation.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/LoadOperation.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,56 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+
+import org.apache.hama.HamaConfiguration;
+
+/**
+ * Load Matrix from a file in HDFS.
+ * 
+ * A = load 'file' as matrix using 'class' ;
+ *
+ */
+public class LoadOperation extends HamaOperation {
+
+  String filename;
+  String asTypename;
+  String classname;
+  
+  public LoadOperation(HamaConfiguration conf, String filename, String typename, 
+      String classname) {
+    super(conf);
+    this.filename = filename;
+    this.asTypename = typename;
+    this.classname = classname;
+  }
+  
+  public LoadOperation(HamaConfiguration conf, String filename, String typename, 
+      String classname, int map, int reduce) {
+    super(conf, map, reduce);
+    this.filename = filename;
+    this.asTypename = typename;
+    this.classname = classname;
+  }
+
+  public Object operate() throws IOException {
+    throw new UnsupportedOperationException("*load* is not supported now.");
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/RandMatrixOperation.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/RandMatrixOperation.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/RandMatrixOperation.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/RandMatrixOperation.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.hama.shell.execution;
+
+import java.io.IOException;
+
+import org.apache.hama.DenseMatrix;
+import org.apache.hama.HamaConfiguration;
+
+/**
+ * Generate a random matrix.
+ * 
+ * A = Matrix.Random #mRows #mColumns
+ *
+ */
+public class RandMatrixOperation extends HamaOperation {
+
+  // rows, columns;
+  int mRows, mColumns;
+  
+  public RandMatrixOperation(HamaConfiguration conf, int rows, int columns) {
+    super(conf);
+    this.mRows = rows;
+    this.mColumns = columns;
+  }
+  
+  public RandMatrixOperation(HamaConfiguration conf, int rows, int columns, 
+      int map, int reduce) {
+    super(conf, map, reduce);
+    this.mRows = rows;
+    this.mColumns = columns;
+  }
+  
+  public Object operate() throws IOException {
+    System.out.println("it is a RandMatrix operation, " +
+    		"[rows="+mRows+"], [columns="+mColumns+"].");
+    return DenseMatrix.random(conf, mRows, mColumns);
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/execution/SaveExpression.java
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/execution/SaveExpression.java?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/execution/SaveExpression.java (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/execution/SaveExpression.java Sun Sep 21 23:14:03 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.hama.shell.execution;
+
+import org.apache.hama.HamaConfiguration;
+import org.apache.hama.Matrix;
+import org.apache.hama.shell.HamaShellEnv;
+
+public class SaveExpression extends HamaExpression {
+
+  Object value;
+  String filename;
+
+  public SaveExpression(HamaConfiguration conf, HamaShellEnv env, Object value,
+      String fileName) {
+    super(conf, env);
+    this.value = value;
+    this.filename = fileName;
+  }
+
+  @Override
+  public void execute() {
+    System.out.println("it is a save expression.");
+    System.out.println("filename=" + filename);
+    if (value instanceof Matrix) {
+      System.out.println((Matrix) value);
+    } else if (value instanceof Double) {
+      System.out.println((Double) value);
+    } else {
+      System.err.println("Unrecognized Type in Save Expression!");
+    }
+    System.err.println("now *save* operation just print the value.");
+  }
+
+}

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/HamaExpressionParser.jjt Sun Sep 21 23:14:03 2008
@@ -0,0 +1,309 @@
+/* Copyright (c) 2006, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright notice,
+ *       this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the Sun Microsystems, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived from
+ *       this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/**
+ * JavaCC file
+ * This file lists the grammar for Hama Expression.
+ * HamaExpressionParser program ouputs a ParseTree given a Valid Hama Expression.
+ */
+options {
+  // Generate non-static functions
+  STATIC = false;
+  // Case is ignored in keywords
+  IGNORE_CASE = true;
+}
+
+PARSER_BEGIN(HamaExpressionParser)
+
+package org.apache.hama.shell.parser.expression;
+
+import java.io.*;
+
+import org.apache.hama.HamaConfiguration;
+import org.apache.hama.shell.HamaShellEnv;
+import org.apache.hama.shell.execution.HamaExpression;
+import org.apache.hama.shell.execution.EvalExpression;
+import org.apache.hama.shell.execution.SaveExpression;
+import org.apache.hama.shell.execution.AlgebraOperation;
+import org.apache.hama.shell.execution.HamaOperation;
+import org.apache.hama.shell.execution.LoadOperation;
+import org.apache.hama.shell.execution.RandMatrixOperation;
+import org.apache.hama.shell.execution.AlgebraOperator;
+
+/** An Expression Grammar. */
+public class HamaExpressionParser {
+
+  private HamaShellEnv shellEnv;
+  private HamaConfiguration conf;
+  
+  public HamaExpressionParser(InputStream in, HamaShellEnv env, HamaConfiguration conf) {
+  	this(in);
+  	this.shellEnv = env;
+  	this.conf = conf;
+  }
+  
+}
+
+PARSER_END(HamaExpressionParser)
+
+
+SKIP :
+{
+  " "
+| "\t"
+| "\n"
+| "\r"
+| <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
+| <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/">
+}
+
+// List all the keywords in HAMA SHELL
+TOKEN : { <LOAD : "load"> }
+TOKEN : { <SAVE : "save"> }
+TOKEN : { <USING : "using"> }
+TOKEN : { <AS : "as"> }
+TOKEN : { <TYPE : "matrix"> }
+TOKEN : { <MAP : "map"> }
+TOKEN : { <REDUCE : "reduce"> }
+TOKEN : { <ADDOP : "+" | "-"> }
+TOKEN : { <MULOP : "*"> }
+TOKEN : { <RANDOMMATRIX : "Matrix.Random"> }
+
+TOKEN:
+{
+ 	<#LETTER : ["a"-"z", "A"-"Z"] >
+|	<#DIGIT : ["0"-"9"] >
+|   <#SPECIALCHAR : ["_"] >
+|   <#FSSPECIALCHAR: ["-", ":", "/"]>
+|	<IDENTIFIER: ( <LETTER> )+ ( <DIGIT> | <LETTER> | <SPECIALCHAR> )* >
+}
+// Define Numeric Constants
+TOKEN :
+{
+ 	< INTEGER: ( <DIGIT> )+ >
+|	< NUMBER: ([ "-","+"])? <FLOAT> | <FLOAT> ( ["e","E"] ([ "-","+"])? <FLOAT> )?>
+| 	< #FLOAT: <INTEGER> ( "." <INTEGER> )? | "." <INTEGER> >
+}
+
+TOKEN : { <QUOTEDSTRING :  "'"
+      (   (~["'","\\","\n","\r"])
+        | ("\\"
+            ( ["n","t","b","r","f","\\","'"] )
+          )
+        | ("\\u"
+            ["0"-"9","A"-"F","a"-"f"]
+            ["0"-"9","A"-"F","a"-"f"]
+            ["0"-"9","A"-"F","a"-"f"]
+	         ["0"-"9","A"-"F","a"-"f"]
+          )
+      )*
+      "'"> }
+
+/** Main production. */
+HamaExpression Start() : {HamaExpression expression = null;}
+{
+  try {
+  ( expression = Expression() ";" )
+  } catch (TokenMgrError e) {
+  	System.err.println(e.toString());
+	// skip all the left tokens when an TokenMgrError happened.
+	// it is a tricky.  maybe not good enough.
+	Token t;
+  	do {
+      t = getNextToken();
+    } while (t!=null);
+  	
+  	expression = null;
+  } catch (ParseException pe) {
+  	System.err.println(pe.toString());
+  	
+  	expression = null;
+  }
+  finally { 
+  	return expression; 
+  }
+}
+
+/** An Expression. */
+HamaExpression Expression() : {HamaExpression expression = null; Token t1, t2, t3; Object value; String filename; HamaOperation operation;}
+{
+  (
+  ( t3=<IDENTIFIER> "=" operation=BasicOperation() 
+  	[ <MAP> t1=<INTEGER>
+  	  {
+  	  	operation.setMapNum(Integer.valueOf(t1.image));
+  	  } 
+  	] 
+  	[ <REDUCE> t2=<INTEGER>
+  	  {
+  	  	operation.setReduceNum(Integer.valueOf(t2.image));
+  	  } 
+  	] 
+  ) 
+  { expression = new EvalExpression(conf, shellEnv, t3.image, operation); } 
+  | 
+  ( <SAVE> value=AliaseName() <AS> filename=FileName() ) 
+  { expression = new SaveExpression(conf, shellEnv, value, filename); }
+  )
+  { return expression; }
+}
+
+/** An Basic Operation. */
+HamaOperation BasicOperation() : {HamaOperation operation;}
+{
+  (
+  operation=AlgebraOp()
+  | 
+  operation=LoadOp()
+  |
+  operation=RandMatrixOp()
+  )
+  { return operation; }
+}
+
+/** A Load Operation. */
+HamaOperation LoadOp() : {String filename; String typename; String classname;}
+{
+  ( <LOAD> filename=FileName() <AS> typename=TypeName() <USING> classname=ClassName() )
+  { return new LoadOperation(conf, filename, typename, classname); }
+}
+
+/** A RandomMatrix Generation Operation. */
+HamaOperation RandMatrixOp() : { Token t1, t2; }
+{
+  ( <RANDOMMATRIX> t1=<INTEGER> t2=<INTEGER> )
+  {
+  	return new RandMatrixOperation(conf, Integer.valueOf(t1.image), Integer.valueOf(t2.image));
+  }
+}
+
+/** An Operation Operation. */
+HamaOperation AlgebraOp() : {AlgebraOperator op;}
+{
+  op = AdditiveOp()
+  { 
+	return new AlgebraOperation(conf, op);
+  } 
+}
+
+/** An Additive Operation. */
+AlgebraOperator AdditiveOp() : {AlgebraOperator op, op1, op2; Token t;}
+{
+  ( op1=MultiplicativeOp() { op = new AlgebraOperator(op1); } ( ( t=<ADDOP> op2=MultiplicativeOp() ){ op.addOpAndOperand(t.image, op2); } )* )
+  { 
+  	return op; 
+  }
+}
+
+/** A Multiplicative Operation. */
+AlgebraOperator MultiplicativeOp() : {AlgebraOperator op, op1, op2; Token t;}
+{
+  ( op1=UnaryOp() { op = new AlgebraOperator(op1); } ( ( t=<MULOP> op2=UnaryOp() ){op.addOpAndOperand(t.image, op2);} )* )
+  {
+  	return op;
+  }
+}
+
+/** A Unary Operation. */
+AlgebraOperator UnaryOp() : {AlgebraOperator op; Object b;}
+{
+  (
+  ( "(" op=AdditiveOp() ")" ) 
+  | 
+  b = AliaseName() { op = new AlgebraOperator(b); }
+  )
+  {
+  	return op;
+  }
+}
+
+// A reference to an alias
+Object AliaseName() : {Token t; Object value;}
+{
+  t=<IDENTIFIER>
+  { 
+	String alias = t.image;
+	
+	value = shellEnv.getAliase(alias);
+	if ((value = shellEnv.getAliase(alias)) == null) {
+		StringBuilder msg = new StringBuilder();
+		msg.append("Unable to find alias: '");
+		msg.append(alias);
+		msg.append("' - Hama Shell Aliases: '");
+		for (String tmpAlias : shellEnv.getAliases().keySet()) {
+			msg.append(tmpAlias);
+			msg.append(",");
+		}
+		msg.append("'");
+		throw new ParseException(msg.toString());
+	}
+	
+	return value;
+  }
+}
+
+/** A Typename. */
+String TypeName() : {Token t;}
+{
+  t=<TYPE>
+  {
+  	return t.image; 
+  }
+}
+
+/** A Filename. */
+String FileName() : {Token t; String filename;}
+{
+  t=<QUOTEDSTRING>
+  { 
+  	filename=t.image.substring(t.image.indexOf("'") + 1, t.image.lastIndexOf("'"));
+  	return filename; 
+  }
+}
+
+/** A ClassName. */
+String ClassName() : {Token t; String classname;}
+{
+  t=<QUOTEDSTRING>
+  {
+  	classname=t.image.substring(t.image.indexOf("'") + 1, t.image.lastIndexOf("'"));
+  	return classname; 
+  }
+}
+
+/** A Constant. */
+Double Constant() : {Token t;}
+{
+  (
+  t=<INTEGER>
+  |
+  t=<NUMBER>
+  )
+  {
+  	return Double.valueOf(t.image);
+  }
+}
\ No newline at end of file

Added: incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/grammar
URL: http://svn.apache.org/viewvc/incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/grammar?rev=697665&view=auto
==============================================================================
--- incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/grammar (added)
+++ incubator/hama/trunk/src/java/org/apache/hama/shell/parser/expression/grammar Sun Sep 21 23:14:03 2008
@@ -0,0 +1,25 @@
+<hamaexpression> := <expr> ";"
+
+<expr> := <IDENTIFIER> "=" <basicoperation> ["MAP" <integer>] ["REDUCE" <integer>] | "SAVE" <IDENTIFIER> "AS" <filename>
+
+<basicoperation> := <algebraop> | <loadop> | <randmatrixop>
+
+<loadop> := "LOAD" <filename> "AS" <typename> "USING" <classname>
+
+<randmatrixop> := "MATRIX.RANDOM" <integer> <integer>
+
+<algebraop> := <additiveop>
+
+<additiveop> := <multiplicationop> ( ( "+" | "-" ) <multiplicationop> )*
+
+<multiplicationop> := <unaryop> ( "*" <unaryop> )*
+
+<unaryop> := "(" <additiveop> ")" | <IDENTIFIER>
+
+<typename> := "matrix"
+
+<filename> := <quotedstring>
+
+<classname> := <quotedstring>
+
+<quotedstring> := "'"<string>"'"



Mime
View raw message