diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java b/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java index 7a3170a..9fbacb5 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveDatabaseMetaData.java @@ -28,6 +28,7 @@ import java.util.jar.Attributes; import org.apache.hadoop.hive.metastore.TableType; +import org.apache.hadoop.hive.ql.udf.CategorizedUDFSummary; import org.apache.hive.service.cli.GetInfoType; import org.apache.hive.service.cli.thrift.TCLIService; import org.apache.hive.service.cli.thrift.TGetCatalogsReq; @@ -475,7 +476,7 @@ public int getMaxUserNameLength() throws SQLException { } public String getNumericFunctions() throws SQLException { - return ""; + return CategorizedUDFSummary.getUDFNumericFunctions(); } public ResultSet getPrimaryKeys(String catalog, String schema, String table) @@ -580,7 +581,7 @@ public String getSearchStringEscape() throws SQLException { } public String getStringFunctions() throws SQLException { - return ""; + return CategorizedUDFSummary.getUDFStringFunctions(); } public ResultSet getSuperTables(String catalog, String schemaPattern, diff --git a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java index 601bcb3..51b8b68 100644 --- a/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java +++ b/jdbc/src/test/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -32,7 +32,6 @@ import java.sql.Statement; import java.sql.Types; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -969,6 +968,7 @@ public void testDescribeTable() throws SQLException { public void testDatabaseMetaData() throws SQLException { DatabaseMetaData meta = con.getMetaData(); + assertTrue(meta instanceof HiveDatabaseMetaData); assertEquals("Hive", meta.getDatabaseProductName()); assertEquals(HiveVersionInfo.getVersion(), meta.getDatabaseProductVersion()); assertEquals(System.getProperty("hive.version"), meta.getDatabaseProductVersion()); @@ -982,6 +982,15 @@ public void testDatabaseMetaData() throws SQLException { assertFalse(meta.supportsMultipleResultSets()); assertFalse(meta.supportsStoredProcedures()); assertTrue(meta.supportsAlterTableWithAddColumn()); + assertEquals( + "ABS(number), ACOS(float), ASIN(float), ATAN(float), CEILING(number), COS(float), DEGREES(number), " + + "EXP(float), FLOOR(number), LOG(float), LOG10(float), PI(), POWER(number, power), RADIANS(number), " + + "RAND(integer), ROUND(number, places), SIGN(number), SIN(float), SQRT(float), TAN(float)", + meta.getNumericFunctions()); + assertEquals( + "ASCII(string), CONCAT(string1, string2 ... stringN), LCASE(string), LENGTH(string), " + + "LTRIM(string), RTRIM(string), SPACE(count), SUBSTRING(string, position[, length])", + meta.getStringFunctions()); } public void testResultSetMetaData() throws SQLException { diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/CategorizedUDFSummary.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/CategorizedUDFSummary.java new file mode 100644 index 0000000..983b5c0 --- /dev/null +++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/CategorizedUDFSummary.java @@ -0,0 +1,38 @@ +package org.apache.hadoop.hive.ql.udf; + +import java.util.Arrays; +import java.util.List; + +/* + * This class summarizes hive's supported scalar function into categories defined by ISO-SQL standard + */ +public class CategorizedUDFSummary { + + private static final List numericFunctions = Arrays.asList(new String[] { + "ABS(number)", "ACOS(float)", "ASIN(float)", "ATAN(float)", "CEILING(number)", "COS(float)", + "DEGREES(number)", "EXP(float)", "FLOOR(number)", "LOG(float)", "LOG10(float)", "PI()", + "POWER(number, power)", "RADIANS(number)", "RAND(integer)", "ROUND(number, places)", + "SIGN(number)", "SIN(float)", "SQRT(float)", "TAN(float)" + }); + + private static final List stringFunctions = Arrays.asList(new String[] { + "ASCII(string)", "CONCAT(string1, string2 ... stringN)", "LCASE(string)", "LENGTH(string)", + "LTRIM(string)", "RTRIM(string)", "SPACE(count)", "SUBSTRING(string, position[, length])" + }); + + public static String getUDFNumericFunctions() { + String ret = ""; + for (String s : numericFunctions) { + ret += s + ", "; + } + return ret.substring(0, ret.lastIndexOf(',')); + } + + public static String getUDFStringFunctions() { + String ret = ""; + for (String s : stringFunctions) { + ret += s + ", "; + } + return ret.substring(0, ret.lastIndexOf(',')); + } +}