package org.apache.hadoop.hive.ql.parse; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import java.io.*; import java.util.*; import org.apache.hadoop.hive.ql.QTestUtil; import org.apache.hadoop.hive.ql.exec.Task; public class $className extends TestCase { private QTestUtil qt; static boolean miniMR = false; static String hadoopVer; static { try { if ("$clusterMode".equals("miniMR")) miniMR = true; hadoopVer = "$hadoopVersion"; } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception in static initialization"); } } public $className(String name) { super(name); qt = null; } @Override protected void setUp() { try { qt = new QTestUtil("$resultsDir.getCanonicalPath()", "$logDir.getCanonicalPath()", miniMR, hadoopVer); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception in setup"); } } public static Test suite() { TestSuite suite = new TestSuite(); #foreach ($qf in $qfiles) #set ($fname = $qf.getName()) #set ($eidx = $fname.length() - 2) #set ($tname = $fname.substring(0, $eidx)) suite.addTest(new $className("testParse_$tname")); #end return suite; } static String debugHint = "\nSee build/ql/tmp/hive.log, " + "or try \"ant test ... -Dtest.silent=false\" to get more logs."; #foreach ($qf in $qfiles) #set ($fname = $qf.getName()) #set ($eidx = $fname.length() - 2) #set ($tname = $fname.substring(0, $eidx)) public void testParse_$tname() throws Exception { try { System.out.println("Begin query: " + "$fname"); qt.addFile("$qf.getCanonicalPath()"); qt.init("$fname"); ASTNode tree = qt.parseQuery("$fname"); int ecode = qt.checkParseResults("$fname", tree); if (ecode != 0) { fail("Parse has unexpected out with error code = " + ecode + debugHint); } List> tasks = qt.analyzeAST(tree); ecode = qt.checkPlan("$fname", tasks); if (ecode != 0) { fail("Semantic Analysis has unexpected output with error code = " + ecode + debugHint); } System.out.println("Done query: " + "$fname"); } catch (Throwable e) { System.out.println("Exception: " + e.getMessage()); e.printStackTrace(); System.out.flush(); fail("Unexpected exception" + debugHint); } assertTrue("Test passed", true); } #end }