You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2015/06/11 08:37:25 UTC

[01/14] incubator-kylin git commit: Metadata check change for 0.6 migration

Repository: incubator-kylin
Updated Branches:
  refs/heads/0.7 724ccf96d -> 6480a9a7a


Metadata check change for 0.6 migration

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

Branch: refs/heads/0.7
Commit: 3647e6bc8363693e98b0a6d15d633ada7c6c7b0a
Parents: f5dc6b9
Author: shaofengshi <sh...@apache.org>
Authored: Fri Jun 5 14:33:03 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Fri Jun 5 14:33:03 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/cube/model/CubeDesc.java   | 46 ++++++++++--
 .../kylin/metadata/MetadataUpgradeTest.java     | 17 +++--
 .../apache/kylin/job/CubeMetadataUpgrade.java   | 77 +++++++++++---------
 3 files changed, 95 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3647e6bc/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
index f236c4e..4959685 100644
--- a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
+++ b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
@@ -456,7 +456,7 @@ public class CubeDesc extends RootPersistentEntity {
         // check all dimension columns are presented on rowkey
         List<TblColRef> dimCols = listDimensionColumnsExcludingDerived();
         if (rowkey.getRowKeyColumns().length != dimCols.size()) {
-            addError("RowKey columns count (" + rowkey.getRowKeyColumns().length + ") does not match dimension columns count (" + dimCols.size() + "). ");
+            addError("RowKey columns count (" + rowkey.getRowKeyColumns().length + ") does not match dimension columns count (" + dimCols.size() + "); rowkeys are " + Arrays.toString(rowkey.getRowKeyColumns()) + ", dimension columns are " + dimCols.toString());
         }
     }
 
@@ -467,7 +467,7 @@ public class CubeDesc extends RootPersistentEntity {
             // init dimension columns
             ArrayList<TblColRef> dimCols = Lists.newArrayList();
             String[] colStrs = dim.getColumn();
-            
+
             // when column is omitted, special case
             if (colStrs == null && dim.isDerived() || ArrayUtils.contains(colStrs, "{FK}")) {
                 for (TblColRef col : join.getForeignKeyColumns()) {
@@ -478,18 +478,18 @@ public class CubeDesc extends RootPersistentEntity {
             else {
                 if (colStrs == null || colStrs.length == 0)
                     throw new IllegalStateException("Dimension column must not be blank " + dim);
-                
+
                 for (String colStr : colStrs) {
                     dimCols.add(initDimensionColRef(dim, colStr));
                 }
-                
+
                 // fill back column ref in hierarchy
                 if (dim.isHierarchy()) {
                     for (int i = 0; i < dimCols.size(); i++)
                         dim.getHierarchy()[i].setColumnRef(dimCols.get(i));
                 }
             }
-            
+
             TblColRef[] dimColArray = (TblColRef[]) dimCols.toArray(new TblColRef[dimCols.size()]);
             dim.setColumnRefs(dimColArray);
 
@@ -518,6 +518,8 @@ public class CubeDesc extends RootPersistentEntity {
                         initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol);
                     }
                 }
+
+                /** disable this code as we don't need fk be derived from pk
                 for (int i = 0; i < pk.length; i++) {
                     int find = ArrayUtils.indexOf(hostCols, pk[i]);
                     if (find >= 0) {
@@ -525,6 +527,40 @@ public class CubeDesc extends RootPersistentEntity {
                         initDerivedMap(hostCols[find], DeriveType.PK_FK, dim, derivedCol);
                     }
                 }
+                 */
+            }
+        }
+
+
+        {
+            // drop those columns (like lookup table's PK but used as a dimension) that can be derived
+            List<TblColRef> derivedCols = Lists.newArrayList();
+            for (TblColRef col : dimensionColumns) {
+                if (isDerived(col) == true)
+                    derivedCols.add(col);
+            }
+
+            if (derivedCols.size() > 0) {
+                dimensionColumns.removeAll(derivedCols);
+            }
+        }
+
+        {
+            // for hierarchy columns, if a column can be derived, use the host col to replace
+            for (DimensionDesc dim : dimensions) {
+                if (dim.isHierarchy()) {
+                    for (int i = 0; i < dim.getColumnRefs().length; i++) {
+                        TblColRef colRef = dim.getColumnRefs()[i];
+                        if (isDerived(colRef)) {
+                            TblColRef[] hostCols = derivedToHostMap.get(colRef).columns;
+                            if (hostCols.length == 1) {
+                               dim.getHierarchy()[i].setColumnRef(hostCols[0]);
+                            } else {
+                                throw new IllegalStateException();
+                            }
+                        }
+                    }
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3647e6bc/cube/src/test/java/org/apache/kylin/metadata/MetadataUpgradeTest.java
----------------------------------------------------------------------
diff --git a/cube/src/test/java/org/apache/kylin/metadata/MetadataUpgradeTest.java b/cube/src/test/java/org/apache/kylin/metadata/MetadataUpgradeTest.java
index 4b1459c..e8feb87 100644
--- a/cube/src/test/java/org/apache/kylin/metadata/MetadataUpgradeTest.java
+++ b/cube/src/test/java/org/apache/kylin/metadata/MetadataUpgradeTest.java
@@ -22,6 +22,7 @@ import java.util.List;
 
 import org.apache.kylin.metadata.model.DataModelDesc;
 import org.apache.kylin.metadata.model.TableDesc;
+import org.apache.kylin.metadata.project.ProjectManager;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -47,7 +48,7 @@ public class MetadataUpgradeTest extends LocalFileMetadataTestCase {
 
     @Before
     public void setUp() throws Exception {
-        createTestMetadata(LOCALMETA_TEST_DATA_V1);
+        createTestMetadata("../meta_upgrade/");
     }
 
     @After
@@ -58,14 +59,16 @@ public class MetadataUpgradeTest extends LocalFileMetadataTestCase {
     @Test
     public void testCubeDescUpgrade() throws Exception {
 
-        String[] sampleCubeDescs = new String[] { "test_kylin_cube_with_slr_desc", "test_kylin_cube_with_slr_left_join_desc", "test_kylin_cube_without_slr_desc", "test_kylin_cube_without_slr_left_join_desc" };
-
-        for (String name : sampleCubeDescs)
-            checkCubeDesc(name);
+        KylinConfig config = KylinConfig.getInstanceFromEnv();
+        MetadataManager.getInstance(config).reload();
+        CubeDescManager.clearCache();
+        CubeDescManager.getInstance(config);
+//        CubeManager cubeManager = CubeManager.getInstance(config);
+//        ProjectManager.getInstance(config);
 
     }
-    
-    @Test
+
+    //@Test
     public void testTableDescUpgrade() throws Exception {
 
         MetadataManager metaMgr = MetadataManager.getInstance(KylinConfig.getInstanceFromEnv());

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/3647e6bc/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
----------------------------------------------------------------------
diff --git a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
index ae03e26..e817dd8 100644
--- a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
+++ b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
@@ -38,10 +38,6 @@ import org.apache.kylin.cube.model.v1.CubeInstance;
 import org.apache.kylin.cube.model.v1.CubeSegment;
 import org.apache.kylin.cube.model.v1.CubeSegmentStatusEnum;
 import org.apache.kylin.cube.model.v1.CubeStatusEnum;
-import org.apache.kylin.dict.DictionaryManager;
-import org.apache.kylin.dict.lookup.SnapshotManager;
-import org.apache.kylin.dict.lookup.SnapshotTable;
-import org.apache.kylin.dict.lookup.TableReader;
 import org.apache.kylin.job.common.HadoopShellExecutable;
 import org.apache.kylin.job.common.MapReduceExecutable;
 import org.apache.kylin.job.common.ShellExecutable;
@@ -69,7 +65,10 @@ import org.apache.kylin.metadata.realization.RealizationType;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -104,13 +103,13 @@ public class CubeMetadataUpgrade {
         upgradeCubeDesc();
         upgradeProjectInstance();
         upgradeCubeInstance();
-      //  upgradeJobInstance();
+        upgradeJobInstance();
 
         verify();
 
     }
 
-    private void verify() {
+    public void verify() {
         MetadataManager.getInstance(config).reload();
         CubeDescManager.clearCache();
         CubeDescManager.getInstance(config);
@@ -629,49 +628,61 @@ public class CubeMetadataUpgrade {
 
     public static void main(String[] args) {
 
-        if (!(args != null && args.length == 1)) {
-            System.out.println("Usage: java CubeMetadataUpgrade <metadata_export_folder>; e.g, /export/kylin/meta");
+        if (!(args != null && (args.length == 1 || args.length == 2))) {
+            System.out.println("Usage: java CubeMetadataUpgrade <metadata_export_folder> <verify>; e.g, /export/kylin/meta ");
             return;
         }
 
         String exportFolder = args[0];
-
-        File oldMetaFolder = new File(exportFolder);
-        if (!oldMetaFolder.exists()) {
-            System.out.println("Provided folder doesn't exist: '" + exportFolder + "'");
-            return;
+        boolean verify = false;
+        if (args.length == 2 && "verify".equals(args[1])) {
+            System.out.println("Only verify the metadata in folder " + exportFolder);
+            verify = true;
         }
 
-        if (!oldMetaFolder.isDirectory()) {
-            System.out.println("Provided folder is not a directory: '" + exportFolder + "'");
-            return;
-        }
+        CubeMetadataUpgrade instance = null;
+        if (verify) {
+            instance = new CubeMetadataUpgrade(exportFolder);
+            instance.verify();
+        } else {
+            File oldMetaFolder = new File(exportFolder);
+            if (!oldMetaFolder.exists()) {
+                System.out.println("Provided folder doesn't exist: '" + exportFolder + "'");
+                return;
+            }
 
+            if (!oldMetaFolder.isDirectory()) {
+                System.out.println("Provided folder is not a directory: '" + exportFolder + "'");
+                return;
+            }
 
-        String newMetadataUrl = oldMetaFolder.getAbsolutePath() + "_v2";
-        try {
-            FileUtils.deleteDirectory(new File(newMetadataUrl));
-            FileUtils.copyDirectory(oldMetaFolder, new File(newMetadataUrl));
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
+            String newMetadataUrl = oldMetaFolder.getAbsolutePath() + "_v2";
+            try {
+                FileUtils.deleteDirectory(new File(newMetadataUrl));
+                FileUtils.copyDirectory(oldMetaFolder, new File(newMetadataUrl));
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
 
-        CubeMetadataUpgrade instance = new CubeMetadataUpgrade(newMetadataUrl);
+            instance = new CubeMetadataUpgrade(newMetadataUrl);
+            instance.upgrade();
+            logger.info("=================================================================");
+            logger.info("Run CubeMetadataUpgrade completed; The following resources have been successfully updated : ");
+            for (String s : instance.updatedResources) {
+                logger.info(s);
+            }
 
-        instance.upgrade();
-        logger.info("=================================================================");
-        logger.info("Run CubeMetadataUpgrade completed; The following resources have been successfully updated in : " + newMetadataUrl);
-        for (String s : instance.updatedResources) {
-            logger.info(s);
         }
 
         logger.info("=================================================================");
-        if (instance.errorMsgs.size() > 0) {
+        if (instance.errorMsgs.size() > 0)
+        {
             logger.info("Here are the error/warning messages, you may need check:");
             for (String s : instance.errorMsgs) {
                 logger.warn(s);
             }
-        } else {
+        } else
+        {
             logger.info("No error or warning messages; The migration is success.");
         }
     }


[02/14] incubator-kylin git commit: Merge branch '0.7-staging' of https://git-wip-us.apache.org/repos/asf/incubator-kylin into 0.7.1-staging

Posted by li...@apache.org.
Merge branch '0.7-staging' of https://git-wip-us.apache.org/repos/asf/incubator-kylin into 0.7.1-staging


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

Branch: refs/heads/0.7
Commit: a6b17c4c8ef0bbee5b72ee7d54a46f444e2cf6f8
Parents: 3647e6b 1dc1a37
Author: shaofengshi <sh...@apache.org>
Authored: Mon Jun 8 14:56:47 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Mon Jun 8 14:56:47 2015 +0800

----------------------------------------------------------------------
 bin/find-hive-dependency.sh                     |   8 +-
 .../org/apache/kylin/common/KylinConfig.java    |  20 +++-
 .../org/apache/kylin/common/util/ClassUtil.java |   7 ++
 .../apache/kylin/common/util/DateFormat.java    | 101 +++++++++++++++++++
 .../apache/kylin/dict/DateStrDictionary.java    |  66 +-----------
 docs/Installation/Hadoop Environment.md         |   7 +-
 .../kylin/invertedindex/index/TableRecord.java  |   9 +-
 .../org/apache/kylin/job/JoinedFlatTable.java   |  50 +++------
 .../kylin/job/common/ShellExecutable.java       |   6 +-
 .../kylin/job/hadoop/hbase/BulkLoadJob.java     |   7 +-
 .../hadoop/hive/CubeJoinedFlatTableDesc.java    |  12 ++-
 .../kylin/job/tools/HadoopStatusGetter.java     |   2 +
 .../kylin/metadata/model/PartitionDesc.java     |  79 +++++++++++----
 .../java/org/apache/kylin/rest/DebugTomcat.java |  87 +++++++++++-----
 .../kylin/storage/hbase/HBaseKeyRange.java      |  14 +--
 .../org/apache/kylin/storage/tuple/Tuple.java   |   6 +-
 16 files changed, 309 insertions(+), 172 deletions(-)
----------------------------------------------------------------------



[06/14] incubator-kylin git commit: Merge branch '0.7-staging' of https://git-wip-us.apache.org/repos/asf/incubator-kylin into 0.7.1-staging

Posted by li...@apache.org.
Merge branch '0.7-staging' of https://git-wip-us.apache.org/repos/asf/incubator-kylin into 0.7.1-staging


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

Branch: refs/heads/0.7
Commit: b32f9b3012d58fb9db27f840ee459b968493054e
Parents: f782391 b3b0f2f
Author: shaofengshi <sh...@apache.org>
Authored: Tue Jun 9 14:20:35 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Tue Jun 9 14:20:35 2015 +0800

----------------------------------------------------------------------
 atopcalcite/pom.xml                             |      2 +-
 bin/find-hbase-dependency.sh                    |     18 +
 common/pom.xml                                  |      2 +-
 cube/pom.xml                                    |      2 +-
 dictionary/pom.xml                              |      2 +-
 .../apache/kylin/dict/TrieDictionaryTest.java   |      2 +-
 .../english-words.80 (scowl-2015.05.18).dic     | 139304 ++++++++++++++++
 .../english-words.80 (scowl-2015.05.18).txt     | 139304 ----------------
 invertedindex/pom.xml                           |      2 +-
 jdbc/pom.xml                                    |      2 +-
 .../org/apache/kylin/jdbc/util/SQLTypeMap.java  |    366 +-
 job/pom.xml                                     |      2 +-
 metadata/pom.xml                                |      2 +-
 pom.xml                                         |      9 +-
 query/pom.xml                                   |      2 +-
 server/pom.xml                                  |      2 +-
 .../kylin/rest/controller/CubeController.java   |      2 +
 .../kylin/rest/response/HBaseResponse.java      |     26 +
 src/main/config/assemblies/source-assembly.xml  |      3 +
 storage/pom.xml                                 |      2 +-
 webapp/app/index.html                           |      1 -
 webapp/app/js/controllers/cubeSchema.js         |      2 +-
 webapp/app/js/controllers/index.js              |     44 -
 webapp/app/less/app.less                        |      2 +-
 webapp/app/less/layout.less                     |      5 +
 webapp/app/partials/cubes/cube_detail.html      |      2 +
 webapp/app/partials/header.html                 |      2 +-
 webapp/app/partials/home.html                   |     65 -
 webapp/app/partials/query/query_detail.html     |      5 +-
 webapp/app/routes.json                          |      9 +-
 webapp/bower.json                               |      2 +-
 31 files changed, 139568 insertions(+), 139627 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b32f9b30/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
----------------------------------------------------------------------


[10/14] incubator-kylin git commit: Migrate 0.6 metadata to v0.7, exclude job history

Posted by li...@apache.org.
Migrate 0.6 metadata to v0.7, exclude job history

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

Branch: refs/heads/0.7
Commit: 00d81f9c6148897950541559df7dad5fbcf3877f
Parents: d38cbd1
Author: shaofengshi <sh...@apache.org>
Authored: Wed Jun 10 16:21:13 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Wed Jun 10 16:21:13 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/cube/CubeDescUpgrader.java | 27 ++++++++++++++++++--
 .../apache/kylin/cube/model/RowKeyColDesc.java  |  2 +-
 .../apache/kylin/job/CubeMetadataUpgrade.java   | 10 +++++++-
 3 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/00d81f9c/cube/src/main/java/org/apache/kylin/cube/CubeDescUpgrader.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/CubeDescUpgrader.java b/cube/src/main/java/org/apache/kylin/cube/CubeDescUpgrader.java
index 139ec2f..5fb99a0 100644
--- a/cube/src/main/java/org/apache/kylin/cube/CubeDescUpgrader.java
+++ b/cube/src/main/java/org/apache/kylin/cube/CubeDescUpgrader.java
@@ -72,20 +72,43 @@ public class CubeDescUpgrader {
 
         updateDimensions(oldModel, newModel);
 
-        updateRowkeyDictionary(oldModel, newModel);
+        updateRowkeyDictionary(newModel);
 
         return newModel;
     }
 
-    private void updateRowkeyDictionary(CubeDesc oldModel, org.apache.kylin.cube.model.CubeDesc newModel) {
+    private void updateRowkeyDictionary(org.apache.kylin.cube.model.CubeDesc newModel) {
 
+        DataModelDesc modelDesc = newModel.getModel();
+        Map<String, String> pkToFK = Maps.newHashMap();
+        for (LookupDesc lookupDesc : modelDesc.getLookups()) {
+            if (lookupDesc.getJoin() != null) {
+                JoinDesc join = lookupDesc.getJoin();
+                for (int i=0; i< join.getForeignKey().length; i++) {
+                    pkToFK.put(join.getPrimaryKey()[i], join.getForeignKey()[i]);
+                }
+            }
+        }
         RowKeyDesc rowKey = newModel.getRowkey();
 
         for (RowKeyColDesc rowkeyCol : rowKey.getRowKeyColumns()) {
             if (rowkeyCol.getDictionary() != null && rowkeyCol.getDictionary().length() > 0)
                 rowkeyCol.setDictionary("true");
+
+            if (pkToFK.containsKey(rowkeyCol.getColumn())) {
+                rowkeyCol.setColumn(pkToFK.get(rowkeyCol.getColumn()));
+            }
         }
 
+        for (String[] aggregationGroup : rowKey.getAggregationGroups()) {
+            for (int i=0; i< aggregationGroup.length; i++) {
+                if (pkToFK.containsKey(aggregationGroup[i])) {
+                    aggregationGroup[i] = pkToFK.get(aggregationGroup[i]);
+                }
+            }
+        }
+
+
     }
 
     private void copyUnChangedProperties(CubeDesc oldModel, org.apache.kylin.cube.model.CubeDesc newModel) {

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/00d81f9c/cube/src/main/java/org/apache/kylin/cube/model/RowKeyColDesc.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/RowKeyColDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/RowKeyColDesc.java
index 7dca61b..b3a2253 100644
--- a/cube/src/main/java/org/apache/kylin/cube/model/RowKeyColDesc.java
+++ b/cube/src/main/java/org/apache/kylin/cube/model/RowKeyColDesc.java
@@ -51,7 +51,7 @@ public class RowKeyColDesc {
         return column;
     }
 
-    void setColumn(String column) {
+    public void setColumn(String column) {
         this.column = column;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/00d81f9c/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
----------------------------------------------------------------------
diff --git a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
index 0b06323..8d4cdc5 100644
--- a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
+++ b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
@@ -63,6 +63,7 @@ import org.apache.kylin.metadata.realization.RealizationStatusEnum;
 import org.apache.kylin.metadata.realization.RealizationType;
 
 import java.io.File;
+import java.io.FileFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
@@ -700,7 +701,14 @@ public class CubeMetadataUpgrade {
             String newMetadataUrl = oldMetaFolder.getAbsolutePath() + "_v2";
             try {
                 FileUtils.deleteDirectory(new File(newMetadataUrl));
-                FileUtils.copyDirectory(oldMetaFolder, new File(newMetadataUrl));
+                FileUtils.copyDirectory(oldMetaFolder, new File(newMetadataUrl), new FileFilter() {
+                    @Override
+                    public boolean accept(File pathname) {
+                        if (pathname.getAbsolutePath().contains(ResourceStore.JOB_PATH_ROOT) || pathname.getAbsolutePath().contains(ResourceStore.JOB_OUTPUT_PATH_ROOT))
+                            return false;
+                        return true;
+                    }
+                });
             } catch (IOException e) {
                 e.printStackTrace();
             }


[05/14] incubator-kylin git commit: Misc minor changes, mainly for 0.6 metadata upgrade

Posted by li...@apache.org.
Misc minor changes, mainly for 0.6 metadata upgrade

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

Branch: refs/heads/0.7
Commit: f78239118f3d6871679f465607d03d825bb22e1b
Parents: a6b17c4
Author: shaofengshi <sh...@apache.org>
Authored: Tue Jun 9 14:19:36 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Tue Jun 9 14:19:36 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/common/KylinConfig.java    |   3 +-
 .../apache/kylin/job/CubeMetadataUpgrade.java   | 117 ++++++++++++-------
 .../org/apache/kylin/job/cube/CubingJob.java    |   2 +-
 .../kylin/metadata/model/PartitionDesc.java     |  27 ++++-
 .../kylin/rest/controller/CubeController.java   |   2 -
 5 files changed, 106 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f7823911/common/src/main/java/org/apache/kylin/common/KylinConfig.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/kylin/common/KylinConfig.java b/common/src/main/java/org/apache/kylin/common/KylinConfig.java
index 08a4d66..cfddbe7 100644
--- a/common/src/main/java/org/apache/kylin/common/KylinConfig.java
+++ b/common/src/main/java/org/apache/kylin/common/KylinConfig.java
@@ -19,7 +19,6 @@
 package org.apache.kylin.common;
 
 import com.google.common.collect.Sets;
-import jodd.util.StringUtil;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.commons.io.IOUtils;
@@ -473,7 +472,7 @@ public class KylinConfig {
 
     private String[] getOptionalStringArray(String prop) {
         final String property = System.getProperty(prop);
-        if (!StringUtil.isBlank(property))
+        if (!StringUtils.isBlank(property))
             return property.split("\\s*,\\s*");
 
         return kylinConfig.getStringArray(prop);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f7823911/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
----------------------------------------------------------------------
diff --git a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
index e817dd8..0b06323 100644
--- a/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
+++ b/job/src/main/java/org/apache/kylin/job/CubeMetadataUpgrade.java
@@ -65,10 +65,7 @@ import org.apache.kylin.metadata.realization.RealizationType;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -103,52 +100,90 @@ public class CubeMetadataUpgrade {
         upgradeCubeDesc();
         upgradeProjectInstance();
         upgradeCubeInstance();
-        upgradeJobInstance();
-
+        //upgradeJobInstance();
         verify();
 
     }
 
-    public void verify() {
+    public void cleanup() {
         MetadataManager.getInstance(config).reload();
-        CubeDescManager.clearCache();
         CubeDescManager.getInstance(config);
         CubeManager cubeManager = CubeManager.getInstance(config);
-        ProjectManager.getInstance(config);
 
-        /*
-        DictionaryManager dictManager = DictionaryManager.getInstance(config);
-        SnapshotManager snapshotManager = SnapshotManager.getInstance(config);
-        List<org.apache.kylin.cube.CubeInstance> allCubes = cubeManager.listAllCubes();
-        for (org.apache.kylin.cube.CubeInstance cube : allCubes) {
-            for (org.apache.kylin.cube.CubeSegment cubeSegment : cube.getSegments()) {
-                Collection<String> snapshots = cubeSegment.getSnapshots().values();
-                for (String s : snapshots) {
-                    try {
-                        SnapshotTable t = snapshotManager.getSnapshotTable(s);
-                        TableReader reader = t.getReader();
-                        while (reader.next()) {
-                            System.out.println(Arrays.toString(reader.getRow()));
+        List<String> activeResourceList = Lists.newArrayList();
+        for (org.apache.kylin.cube.CubeInstance cube : cubeManager.listAllCubes()) {
+            for (org.apache.kylin.cube.CubeSegment segment : cube.getSegments()) {
+                activeResourceList.addAll(segment.getSnapshotPaths());
+                activeResourceList.addAll(segment.getDictionaryPaths());
+            }
+        }
+
+        List<String> toDeleteResource = Lists.newArrayList();
+        List<String> activeResource = Lists.newArrayList();
+        try {
+            ArrayList<String> snapshotTables = getStore().listResources(ResourceStore.SNAPSHOT_RESOURCE_ROOT);
+
+            for (String snapshotTable : snapshotTables) {
+                ArrayList<String> snapshotNames = getStore().listResources(snapshotTable);
+                if (snapshotNames != null)
+                    for (String snapshot : snapshotNames) {
+                        if (!activeResourceList.contains(snapshot)) {
+                            toDeleteResource.add(snapshot);
+
+                        } else {
+                            activeResource.add(snapshot);
                         }
-                    } catch (IOException e) {
-                        e.printStackTrace();
                     }
-                }
-
-                Collection<String> dicts = cubeSegment.getDictionaries().values();
-                for (String s : dicts) {
-                    try {
-                        org.apache.kylin.dict.Dictionary<?> dict = dictManager.getDictionary(s);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
 
-                        System.out.println(dict.getMaxId());
-                    } catch (IOException e) {
-                        e.printStackTrace();
+        try {
+            ArrayList<String> dictTables = getStore().listResources(ResourceStore.DICT_RESOURCE_ROOT);
+
+            for (String table : dictTables) {
+                ArrayList<String> tableColNames = getStore().listResources(table);
+                if (tableColNames != null)
+                    for (String tableCol : tableColNames) {
+                        ArrayList<String> dictionaries = getStore().listResources(tableCol);
+                        if (dictionaries != null)
+                            for (String dict : dictionaries)
+                                if (!activeResourceList.contains(dict)) {
+                                    toDeleteResource.add(dict);
+                                } else {
+                                    activeResource.add(dict);
+                                }
                     }
-                }
             }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+
+        if (toDeleteResource.size() > 0) {
+            logger.info("The following resources is never needed, will be dropped, number :" + toDeleteResource.size());
 
+            for (String s : toDeleteResource) {
+                logger.info(s);
+                try {
+                    getStore().deleteResource(s);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
         }
-        */
+
+    }
+
+    public void verify() {
+        MetadataManager.getInstance(config).reload();
+        CubeDescManager.clearCache();
+        CubeDescManager.getInstance(config);
+        CubeManager cubeManager = CubeManager.getInstance(config);
+        ProjectManager.getInstance(config);
+        //cleanup();
+
     }
 
     private List<String> listResourceStore(String pathRoot) {
@@ -478,9 +513,15 @@ public class CubeMetadataUpgrade {
 
     private void upgradeJobInstance(String path) throws IOException {
         JobInstance job = getStore().getResource(path, JobInstance.class, new JsonSerializer<JobInstance>(JobInstance.class));
+        long lastModified = job.getLastModified();
+        if (System.currentTimeMillis() - lastModified > 2592000000l) {
+            // old than 30 days, skip;
+            return;
+        }
         CubingJob cubingJob = new CubingJob();
         cubingJob.setId(job.getId());
         cubingJob.setName(job.getName());
+        cubingJob.setCubeName(job.getRelatedCube());
         cubingJob.setSubmitter(job.getSubmitter());
         for (JobInstance.JobStep step : job.getSteps()) {
             final AbstractExecutable executable = parseToExecutable(step);
@@ -675,14 +716,12 @@ public class CubeMetadataUpgrade {
         }
 
         logger.info("=================================================================");
-        if (instance.errorMsgs.size() > 0)
-        {
+        if (instance.errorMsgs.size() > 0) {
             logger.info("Here are the error/warning messages, you may need check:");
             for (String s : instance.errorMsgs) {
                 logger.warn(s);
             }
-        } else
-        {
+        } else {
             logger.info("No error or warning messages; The migration is success.");
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f7823911/job/src/main/java/org/apache/kylin/job/cube/CubingJob.java
----------------------------------------------------------------------
diff --git a/job/src/main/java/org/apache/kylin/job/cube/CubingJob.java b/job/src/main/java/org/apache/kylin/job/cube/CubingJob.java
index bf6ae11..483b44d 100644
--- a/job/src/main/java/org/apache/kylin/job/cube/CubingJob.java
+++ b/job/src/main/java/org/apache/kylin/job/cube/CubingJob.java
@@ -47,7 +47,7 @@ public class CubingJob extends DefaultChainedExecutable {
     public static final String MAP_REDUCE_WAIT_TIME = "mapReduceWaitTime";
 
 
-    void setCubeName(String name) {
+    public void setCubeName(String name) {
         setParam(CUBE_INSTANCE_NAME, name);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f7823911/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java b/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
index 73db41f..b943622 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
@@ -73,7 +73,7 @@ public class PartitionDesc {
             throw new IllegalStateException("The 'partition_date_column' format is invalid: " + partitionDateColumn + ", it should be {db}.{table}.{column}.");
         }
         
-        partitionConditionBuilder = (IPartitionConditionBuilder) ClassUtil.newInstance(partitionConditionBuilderClz);
+       partitionConditionBuilder = (IPartitionConditionBuilder) ClassUtil.newInstance(partitionConditionBuilderClz);
     }
 
     public boolean isPartitioned() {
@@ -144,4 +144,29 @@ public class PartitionDesc {
         }
 
     }
+
+    public static class YearMonthDayPartitionConditionBuilder implements PartitionDesc.IPartitionConditionBuilder {
+
+        @Override
+        public String buildDateRangeCondition(PartitionDesc partDesc, long l, long l1, Map<String, String> map) {
+
+            String partitionColumnName = partDesc.getPartitionDateColumn();
+            String partitionTableName;
+
+            // convert to use table alias
+            int indexOfDot = partitionColumnName.lastIndexOf(".");
+            if (indexOfDot > 0) {
+                partitionTableName = partitionColumnName.substring(0, indexOfDot);
+            } else {
+                throw new IllegalStateException("The partitionColumnName is invalid: " + partitionColumnName);
+            }
+
+            if (map.containsKey(partitionTableName)) {
+                partitionTableName = map.get(partitionTableName);
+            }
+
+            String sql = String.format("CONCAT(%s.YEAR,'-',%s.MONTH,'-',%s.DAY)", partitionTableName, partitionTableName, partitionTableName);
+            return sql;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f7823911/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java b/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
index 51224b8..d56fb4a 100644
--- a/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
+++ b/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
@@ -52,7 +52,6 @@ import org.apache.kylin.rest.response.HBaseResponse;
 import org.apache.kylin.rest.service.CubeService;
 import org.apache.kylin.rest.service.JobService;
 import org.apache.kylin.storage.hbase.coprocessor.observer.ObserverEnabler;
-import org.quartz.SchedulerException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -190,7 +189,6 @@ public class CubeController extends BasicController {
      *
      * @param cubeName Cube ID
      * @return
-     * @throws SchedulerException
      * @throws IOException
      */
     @RequestMapping(value = "/{cubeName}/rebuild", method = {RequestMethod.PUT})


[14/14] incubator-kylin git commit: KYLIN-812 Upgrade to Calcite 0.9.2

Posted by li...@apache.org.
KYLIN-812 Upgrade to Calcite 0.9.2


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

Branch: refs/heads/0.7
Commit: 6480a9a7ab2241e068bec8e3927adb483c4208fc
Parents: f37360d
Author: Li, Yang <ya...@ebay.com>
Authored: Thu Jun 11 10:49:00 2015 +0800
Committer: Li, Yang <ya...@ebay.com>
Committed: Thu Jun 11 10:50:42 2015 +0800

----------------------------------------------------------------------
 .../hydromatic/optiq/runtime/SqlFunctions.java  | 3173 +++++++++---------
 .../eigenbase/sql2rel/SqlToRelConverter.java    |    4 +-
 .../org/apache/kylin/cube/model/CubeDesc.java   |   33 -
 .../org/apache/kylin/jdbc/KylinPrepare.java     |  201 +-
 pom.xml                                         |    2 +-
 .../kylin/query/relnode/OLAPAggregateRel.java   |    5 +-
 .../org/apache/kylin/query/relnode/OLAPRel.java |    3 +-
 7 files changed, 1741 insertions(+), 1680 deletions(-)
----------------------------------------------------------------------



[07/14] incubator-kylin git commit: rollback KYLIN-658, always use FK instead PK in row key and aggregation group

Posted by li...@apache.org.
rollback KYLIN-658, always use FK instead PK in row key and aggregation group

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

Branch: refs/heads/0.7
Commit: 30f4c6ab31dfb20e4dc7f5e78c5772e30e04d64b
Parents: b32f9b3
Author: shaofengshi <sh...@apache.org>
Authored: Tue Jun 9 17:31:38 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Tue Jun 9 17:31:38 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/cube/model/CubeDesc.java   | 11 ++++++++-
 .../org/apache/kylin/cube/model/RowKeyDesc.java |  1 +
 .../kylin/metadata/model/PartitionDesc.java     | 25 +++++++++++++++-----
 3 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/30f4c6ab/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
index 4959685..a810376 100644
--- a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
+++ b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
@@ -609,8 +609,17 @@ public class CubeDesc extends RootPersistentEntity {
         ColumnDesc col = table.findColumnByName(colName);
         if (col == null)
             throw new IllegalArgumentException("No column '" + colName + "' found in table " + table);
-        
+
         TblColRef ref = new TblColRef(col);
+
+        // always use FK instead PK, FK could be shared by more than one lookup tables
+        JoinDesc join = dim.getJoin();
+        if (join != null) {
+            int idx = ArrayUtils.indexOf(join.getPrimaryKeyColumns(), ref);
+            if (idx >= 0) {
+                ref = join.getForeignKeyColumns()[idx];
+            }
+        }
         return initDimensionColRef(ref);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/30f4c6ab/cube/src/main/java/org/apache/kylin/cube/model/RowKeyDesc.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/RowKeyDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/RowKeyDesc.java
index b1e0b53..0d2c238 100644
--- a/cube/src/main/java/org/apache/kylin/cube/model/RowKeyDesc.java
+++ b/cube/src/main/java/org/apache/kylin/cube/model/RowKeyDesc.java
@@ -154,6 +154,7 @@ public class RowKeyDesc {
 
     private RowKeyColDesc getColDesc(TblColRef col) {
         RowKeyColDesc desc = columnMap.get(col);
+
         if (desc == null)
             throw new NullPointerException("Column " + col + " does not exist in row key desc");
         return desc;

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/30f4c6ab/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
----------------------------------------------------------------------
diff --git a/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java b/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
index b943622..42a752f 100644
--- a/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
+++ b/metadata/src/main/java/org/apache/kylin/metadata/model/PartitionDesc.java
@@ -145,10 +145,14 @@ public class PartitionDesc {
 
     }
 
+    /**
+     * Another implementation of IPartitionConditionBuilder, for the fact tables which have three partition columns "YEAR", "MONTH", and "DAY"; This
+     * class will concat the three columns into yyyy-MM-dd format for query hive;
+     */
     public static class YearMonthDayPartitionConditionBuilder implements PartitionDesc.IPartitionConditionBuilder {
 
         @Override
-        public String buildDateRangeCondition(PartitionDesc partDesc, long l, long l1, Map<String, String> map) {
+        public String buildDateRangeCondition(PartitionDesc partDesc, long startInclusive, long endExclusive, Map<String, String> tableAlias) {
 
             String partitionColumnName = partDesc.getPartitionDateColumn();
             String partitionTableName;
@@ -156,17 +160,26 @@ public class PartitionDesc {
             // convert to use table alias
             int indexOfDot = partitionColumnName.lastIndexOf(".");
             if (indexOfDot > 0) {
-                partitionTableName = partitionColumnName.substring(0, indexOfDot);
+                partitionTableName = partitionColumnName.substring(0, indexOfDot).toUpperCase();
             } else {
                 throw new IllegalStateException("The partitionColumnName is invalid: " + partitionColumnName);
             }
 
-            if (map.containsKey(partitionTableName)) {
-                partitionTableName = map.get(partitionTableName);
+            if (tableAlias.containsKey(partitionTableName)) {
+                partitionTableName = tableAlias.get(partitionTableName);
             }
 
-            String sql = String.format("CONCAT(%s.YEAR,'-',%s.MONTH,'-',%s.DAY)", partitionTableName, partitionTableName, partitionTableName);
-            return sql;
+            String concatField = String.format("CONCAT(%s.YEAR,'-',%s.MONTH,'-',%s.DAY)", partitionTableName, partitionTableName, partitionTableName);
+            StringBuilder builder = new StringBuilder();
+
+            if (startInclusive > 0) {
+                builder.append(concatField + " >= '" + DateFormat.formatToDateStr(startInclusive) + "' ");
+                builder.append("AND ");
+            }
+            builder.append(concatField + " < '" + DateFormat.formatToDateStr(endExclusive) + "'");
+
+
+            return builder.toString();
         }
     }
 }


[12/14] incubator-kylin git commit: KYLIN-812 Upgrade to Calcite 0.9.2

Posted by li...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/atopcalcite/src/main/java/org/eigenbase/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
diff --git a/atopcalcite/src/main/java/org/eigenbase/sql2rel/SqlToRelConverter.java b/atopcalcite/src/main/java/org/eigenbase/sql2rel/SqlToRelConverter.java
index 796640c..dd7ee01 100644
--- a/atopcalcite/src/main/java/org/eigenbase/sql2rel/SqlToRelConverter.java
+++ b/atopcalcite/src/main/java/org/eigenbase/sql2rel/SqlToRelConverter.java
@@ -45,6 +45,7 @@ import org.eigenbase.util.mapping.Mappings;
 import org.eigenbase.util14.*;
 
 import net.hydromatic.linq4j.Ord;
+
 import net.hydromatic.optiq.ModifiableTable;
 import net.hydromatic.optiq.TranslatableTable;
 import net.hydromatic.optiq.prepare.Prepare;
@@ -65,7 +66,6 @@ import static org.eigenbase.util.Static.RESOURCE;
  * <p>The public entry points are: {@link #convertQuery},
  * {@link #convertExpression(SqlNode)}.
  */
-@SuppressWarnings({"unused", "rawtypes", "unchecked", "incomplete-switch", "deprecation"})
 public class SqlToRelConverter {
   //~ Static fields/initializers ---------------------------------------------
 
@@ -1487,7 +1487,7 @@ public class SqlToRelConverter {
    *                                     node, only register it if it's a scalar
    *                                     subquery
    */
-private void findSubqueries(
+  private void findSubqueries(
       Blackboard bb,
       SqlNode node,
       RelOptUtil.Logic logic,

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
----------------------------------------------------------------------
diff --git a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
index a810376..b03268f 100644
--- a/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
+++ b/cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
@@ -530,39 +530,6 @@ public class CubeDesc extends RootPersistentEntity {
                  */
             }
         }
-
-
-        {
-            // drop those columns (like lookup table's PK but used as a dimension) that can be derived
-            List<TblColRef> derivedCols = Lists.newArrayList();
-            for (TblColRef col : dimensionColumns) {
-                if (isDerived(col) == true)
-                    derivedCols.add(col);
-            }
-
-            if (derivedCols.size() > 0) {
-                dimensionColumns.removeAll(derivedCols);
-            }
-        }
-
-        {
-            // for hierarchy columns, if a column can be derived, use the host col to replace
-            for (DimensionDesc dim : dimensions) {
-                if (dim.isHierarchy()) {
-                    for (int i = 0; i < dim.getColumnRefs().length; i++) {
-                        TblColRef colRef = dim.getColumnRefs()[i];
-                        if (isDerived(colRef)) {
-                            TblColRef[] hostCols = derivedToHostMap.get(colRef).columns;
-                            if (hostCols.length == 1) {
-                               dim.getHierarchy()[i].setColumnRef(hostCols[0]);
-                            } else {
-                                throw new IllegalStateException();
-                            }
-                        }
-                    }
-                }
-            }
-        }
     }
 
     private String[][] splitDerivedColumnAndExtra(String[] derived) {

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/jdbc/src/main/java/org/apache/kylin/jdbc/KylinPrepare.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinPrepare.java b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinPrepare.java
index 7f20d5b..0e4fb35 100644
--- a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinPrepare.java
+++ b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinPrepare.java
@@ -1,98 +1,103 @@
-/*
- * 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.kylin.jdbc;
-
-import java.util.List;
-
-import net.hydromatic.avatica.AvaticaParameter;
-import net.hydromatic.avatica.AvaticaPrepareResult;
-import net.hydromatic.avatica.ColumnMetaData;
-import net.hydromatic.avatica.Cursor;
-import net.hydromatic.linq4j.Enumerator;
-import net.hydromatic.optiq.runtime.EnumeratorCursor;
-
-/**
- * Interface of kylin prepare statement implementation
- * 
- * @author xduo
- * 
- */
-public interface KylinPrepare {
-
-    PrepareResult prepare(String sql);
-
-    /**
-     * The result of preparing a query. It gives the Avatica driver framework
-     * the information it needs to create a prepared statement, or to execute a
-     * statement directly, without an explicit prepare step.
-     */
-    public static class PrepareResult implements AvaticaPrepareResult {
-        public final String sql; // for debug
-        public final ColumnMetaData.StructType structType;
-        public final Enumerator<Object[]> enumerator;
-        public final List<AvaticaParameter> parameterList;
-
-        public PrepareResult(String sql, List<AvaticaParameter> parameterList, Enumerator<Object[]> enumerator, ColumnMetaData.StructType structType) {
-            super();
-            this.sql = sql;
-            this.parameterList = parameterList;
-            this.enumerator = enumerator;
-            this.structType = structType;
-        }
-
-        public Cursor createCursor() {
-            return new EnumeratorCursor<Object[]>(enumerator) {
-                @Override
-                protected Getter createGetter(int ordinal) {
-                    return new ArrayEnumeratorGetter(ordinal);
-                }
-
-                /**
-                 * Row field accessor via index
-                 */
-                class ArrayEnumeratorGetter extends AbstractGetter {
-                    protected final int field;
-
-                    public ArrayEnumeratorGetter(int field) {
-                        this.field = field;
-                    }
-
-                    public Object getObject() {
-                        Object o = current()[field];
-                        wasNull[0] = o == null;
-                        return o;
-                    }
-                }
-            };
-        }
-
-        public List<ColumnMetaData> getColumnList() {
-            return structType.columns;
-        }
-
-        public List<AvaticaParameter> getParameterList() {
-            return parameterList;
-        }
-
-        public String getSql() {
-            return sql;
-        }
-    }
-
-}
+/*
+ * 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.kylin.jdbc;
+
+import java.util.List;
+import java.util.Map;
+
+import net.hydromatic.avatica.AvaticaParameter;
+import net.hydromatic.avatica.AvaticaPrepareResult;
+import net.hydromatic.avatica.ColumnMetaData;
+import net.hydromatic.avatica.Cursor;
+import net.hydromatic.linq4j.Enumerator;
+import net.hydromatic.optiq.runtime.EnumeratorCursor;
+
+/**
+ * Interface of kylin prepare statement implementation
+ * 
+ * @author xduo
+ * 
+ */
+public interface KylinPrepare {
+
+    PrepareResult prepare(String sql);
+
+    /**
+     * The result of preparing a query. It gives the Avatica driver framework
+     * the information it needs to create a prepared statement, or to execute a
+     * statement directly, without an explicit prepare step.
+     */
+    public static class PrepareResult implements AvaticaPrepareResult {
+        public final String sql; // for debug
+        public final ColumnMetaData.StructType structType;
+        public final Enumerator<Object[]> enumerator;
+        public final List<AvaticaParameter> parameterList;
+
+        public PrepareResult(String sql, List<AvaticaParameter> parameterList, Enumerator<Object[]> enumerator, ColumnMetaData.StructType structType) {
+            super();
+            this.sql = sql;
+            this.parameterList = parameterList;
+            this.enumerator = enumerator;
+            this.structType = structType;
+        }
+
+        public Cursor createCursor() {
+            return new EnumeratorCursor<Object[]>(enumerator) {
+                @Override
+                protected Getter createGetter(int ordinal) {
+                    return new ArrayEnumeratorGetter(ordinal);
+                }
+
+                /**
+                 * Row field accessor via index
+                 */
+                class ArrayEnumeratorGetter extends AbstractGetter {
+                    protected final int field;
+
+                    public ArrayEnumeratorGetter(int field) {
+                        this.field = field;
+                    }
+
+                    public Object getObject() {
+                        Object o = current()[field];
+                        wasNull[0] = o == null;
+                        return o;
+                    }
+                }
+            };
+        }
+
+        public List<ColumnMetaData> getColumnList() {
+            return structType.columns;
+        }
+
+        public List<AvaticaParameter> getParameterList() {
+            return parameterList;
+        }
+
+        public Map<String, Object> getInternalParameters() {
+            return null;
+        }
+
+        public String getSql() {
+            return sql;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index cf776db..5748328 100644
--- a/pom.xml
+++ b/pom.xml
@@ -84,7 +84,7 @@
         <spring.framework.version>3.1.2.RELEASE</spring.framework.version>
 
         <!-- Optiq Version -->
-        <optiq.version>0.9.1-incubating</optiq.version>
+        <optiq.version>0.9.2-incubating</optiq.version>
         <linq4j.version>0.4</linq4j.version>
 
         <!-- Metrics Codahale Version -->

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
index 83723c2..e228d82 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAggregateRel.java
@@ -49,6 +49,7 @@ import org.eigenbase.reltype.RelDataTypeFactory;
 import org.eigenbase.reltype.RelDataTypeField;
 import org.eigenbase.sql.SqlAggFunction;
 import org.eigenbase.sql.SqlIdentifier;
+import org.eigenbase.sql.fun.SqlStdOperatorTable;
 import org.eigenbase.sql.fun.SqlSumEmptyIsZeroAggFunction;
 import org.eigenbase.sql.parser.SqlParserPos;
 import org.eigenbase.sql.type.InferTypes;
@@ -59,6 +60,7 @@ import org.eigenbase.sql.validate.SqlUserDefinedAggFunction;
 import org.eigenbase.util.Util;
 
 import com.google.common.base.Preconditions;
+
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.TableDesc;
 import org.apache.kylin.metadata.model.FunctionDesc;
@@ -304,7 +306,8 @@ public class OLAPAggregateRel extends AggregateRelBase implements OLAPRel, Enume
         if (func.isCountDistinct()) {
             newAgg = createHyperLogLogAggFunction(fieldType);
         } else if (func.isCount()) {
-            newAgg = new SqlSumEmptyIsZeroAggFunction(fieldType);
+            //newAgg = new SqlSumEmptyIsZeroAggFunction(fieldType);
+            newAgg = SqlStdOperatorTable.SUM0;
         }
 
         // rebuild aggregate call

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
----------------------------------------------------------------------
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
index 3c34ab4..06cad92 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPRel.java
@@ -18,6 +18,7 @@
 
 package org.apache.kylin.query.relnode;
 
+import java.util.LinkedHashMap;
 import java.util.Stack;
 
 import net.hydromatic.optiq.rules.java.EnumerableRel;
@@ -139,7 +140,7 @@ public interface OLAPRel extends RelNode {
         private OLAPContext parentContext;
 
         public JavaImplementor(EnumerableRelImplementor enumImplementor) {
-            super(enumImplementor.getRexBuilder());
+            super(enumImplementor.getRexBuilder(), new LinkedHashMap<String, Object>());
         }
 
         public OLAPContext getParentContext() {


[08/14] incubator-kylin git commit: rm json editor

Posted by li...@apache.org.
rm json editor


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

Branch: refs/heads/0.7
Commit: f3cc299365298cb944b70dc7b23c3a618fd701c1
Parents: 30f4c6a
Author: jiazhong <ji...@ebay.com>
Authored: Tue Jun 9 18:07:58 2015 +0800
Committer: jiazhong <ji...@ebay.com>
Committed: Tue Jun 9 18:07:58 2015 +0800

----------------------------------------------------------------------
 webapp/app/partials/cubes/cubes.html              |  1 -
 webapp/app/partials/tables/source_metadata.html   | 15 ---------------
 webapp/app/partials/tables/source_table_tree.html | 17 +++++++++++++++++
 3 files changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f3cc2993/webapp/app/partials/cubes/cubes.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/cubes/cubes.html b/webapp/app/partials/cubes/cubes.html
index fbf0281..618dbce 100644
--- a/webapp/app/partials/cubes/cubes.html
+++ b/webapp/app/partials/cubes/cubes.html
@@ -47,7 +47,6 @@
         </form>
     </div>
     <div class="pull-right">
-        <a class="btn btn-primary btn-sm" href="cubes/add/json" ng-if="userService.hasRole('ROLE_ADMIN')"><i class="fa fa-pencil-square-o"></i> Json Editor</a>
         <a class="btn btn-primary btn-sm" href="cubes/add"  ng-if="userService.hasRole('ROLE_MODELER')" id="addCubeButton"><i class="fa fa-plus"></i> Cube</a>
     </div>
 </div>

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f3cc2993/webapp/app/partials/tables/source_metadata.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/tables/source_metadata.html b/webapp/app/partials/tables/source_metadata.html
index 62b4d0f..73c7b3c 100755
--- a/webapp/app/partials/tables/source_metadata.html
+++ b/webapp/app/partials/tables/source_metadata.html
@@ -165,21 +165,6 @@
         </div>
     </div>
 
-    <script type="text/ng-template" id="addHiveTable.html">
-        <div class="modal-header">
-            <h4>Load Hive Table Metadata</h4>
-        </div>
-        <div class="modal-body">
-            <span><strong>Project: </strong>{{ $parent.projectName!=null?$parent.projectName:'NULL'}}</span>
-            <label for="tables"> Table Names:(Seperate with comma)</label>
-            <textarea ng-model="$parent.tableNames" class="form-control" id="tables"
-                      placeholder="table1,table2  By default,system will choose 'Default' as database,you can specify database like this 'database.table'"></textarea>
-        </div>
-        <div class="modal-footer">
-            <button class="btn btn-primary" ng-click="add()">Sync</button>
-            <button class="btn btn-primary" ng-click="cancel()">Cancel</button>
-        </div>
-    </script>
 </div>
 
 <div ng-include="'partials/projects/project_create.html'"></div>

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f3cc2993/webapp/app/partials/tables/source_table_tree.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/tables/source_table_tree.html b/webapp/app/partials/tables/source_table_tree.html
index f381077..2b40ab1 100755
--- a/webapp/app/partials/tables/source_table_tree.html
+++ b/webapp/app/partials/tables/source_table_tree.html
@@ -44,3 +44,20 @@
         </treecontrol>
     </div>
 </div>
+
+
+<script type="text/ng-template" id="addHiveTable.html">
+  <div class="modal-header">
+    <h4>Load Hive Table Metadata</h4>
+  </div>
+  <div class="modal-body">
+    <span><strong>Project: </strong>{{ $parent.projectName!=null?$parent.projectName:'NULL'}}</span>
+    <label for="tables"> Table Names:(Seperate with comma)</label>
+            <textarea ng-model="$parent.tableNames" class="form-control" id="tables"
+                      placeholder="table1,table2  By default,system will choose 'Default' as database,you can specify database like this 'database.table'"></textarea>
+  </div>
+  <div class="modal-footer">
+    <button class="btn btn-primary" ng-click="add()">Sync</button>
+    <button class="btn btn-primary" ng-click="cancel()">Cancel</button>
+  </div>
+</script>


[13/14] incubator-kylin git commit: KYLIN-812 Upgrade to Calcite 0.9.2

Posted by li...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6480a9a7/atopcalcite/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
----------------------------------------------------------------------
diff --git a/atopcalcite/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java b/atopcalcite/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
index ad65aa2..db99c83 100644
--- a/atopcalcite/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
+++ b/atopcalcite/src/main/java/net/hydromatic/optiq/runtime/SqlFunctions.java
@@ -52,1569 +52,1654 @@ import java.util.regex.Pattern;
  * If null arguments are possible, the code-generation framework checks for
  * nulls before calling the functions.</p>
  */
-@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
+@SuppressWarnings("UnnecessaryUnboxing")
 @Deterministic
 public class SqlFunctions {
-    private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("0.0E0");
+  private static final DecimalFormat DOUBLE_FORMAT =
+      new DecimalFormat("0.0E0");
 
-    /** The julian date of the epoch, 1970-01-01. */
-    public static final int EPOCH_JULIAN = 2440588;
+  /** The julian date of the epoch, 1970-01-01. */
+  public static final int EPOCH_JULIAN = 2440588;
 
-    private static final TimeZone LOCAL_TZ = TimeZone.getDefault();
+  private static final TimeZone LOCAL_TZ = TimeZone.getDefault();
 
-    private static final Function1<List<Object>, Enumerable<Object>> LIST_AS_ENUMERABLE = new Function1<List<Object>, Enumerable<Object>>() {
+  private static final Function1<List<Object>, Enumerable<Object>>
+  LIST_AS_ENUMERABLE =
+      new Function1<List<Object>, Enumerable<Object>>() {
         public Enumerable<Object> apply(List<Object> list) {
-            return Linq4j.asEnumerable(list);
+          return Linq4j.asEnumerable(list);
         }
-    };
-
-    private SqlFunctions() {
-    }
-
-    /** SQL SUBSTRING(string FROM ... FOR ...) function. */
-    public static String substring(String s, int from, int for_) {
-        return s.substring(from - 1, Math.min(from - 1 + for_, s.length()));
-    }
-
-    /** SQL SUBSTRING(string FROM ...) function. */
-    public static String substring(String s, int from) {
-        return s.substring(from - 1);
-    }
-
-    /** SQL UPPER(string) function. */
-    public static String upper(String s) {
-        return s.toUpperCase();
-    }
-
-    /** SQL LOWER(string) function. */
-    public static String lower(String s) {
-        return s.toLowerCase();
-    }
-
-    /** SQL INITCAP(string) function. */
-    public static String initcap(String s) {
-        // Assumes Alpha as [A-Za-z0-9]
-        // white space is treated as everything else.
-        final int len = s.length();
-        boolean start = true;
-        final StringBuilder newS = new StringBuilder();
-
-        for (int i = 0; i < len; i++) {
-            char curCh = s.charAt(i);
-            final int c = (int) curCh;
-            if (start) { // curCh is whitespace or first character of word.
-                if (c > 47 && c < 58) { // 0-9
-                    start = false;
-                } else if (c > 64 && c < 91) { // A-Z
-                    start = false;
-                } else if (c > 96 && c < 123) { // a-z
-                    start = false;
-                    curCh = (char) (c - 32); // Uppercase this character
-                }
-                // else {} whitespace
-            } else { // Inside of a word or white space after end of word.
-                if (c > 47 && c < 58) { // 0-9
-                    // noop
-                } else if (c > 64 && c < 91) { // A-Z
-                    curCh = (char) (c + 32); // Lowercase this character
-                } else if (c > 96 && c < 123) { // a-z
-                    // noop
-                } else { // whitespace
-                    start = true;
-                }
-            }
-            newS.append(curCh);
-        } // for each character in s
-        return newS.toString();
-    }
-
-    /** SQL CHARACTER_LENGTH(string) function. */
-    public static int charLength(String s) {
-        return s.length();
-    }
-
-    /** SQL {@code string || string} operator. */
-    public static String concat(String s0, String s1) {
-        return s0 + s1;
-    }
-
-    /** SQL {@code binary || binary} operator. */
-    public static ByteString concat(ByteString s0, ByteString s1) {
-        return s0.concat(s1);
-    }
-
-    /** SQL {@code RTRIM} function applied to string. */
-    public static String rtrim(String s) {
-        return trim_(s, false, true, ' ');
-    }
-
-    /** SQL {@code LTRIM} function. */
-    public static String ltrim(String s) {
-        return trim_(s, true, false, ' ');
-    }
-
-    /** SQL {@code TRIM(... seek FROM s)} function. */
-    public static String trim(boolean leading, boolean trailing, String seek, String s) {
-        return trim_(s, leading, trailing, seek.charAt(0));
-    }
-
-    /** SQL {@code TRIM} function. */
-    private static String trim_(String s, boolean left, boolean right, char c) {
-        int j = s.length();
-        if (right) {
-            for (;;) {
-                if (j == 0) {
-                    return "";
-                }
-                if (s.charAt(j - 1) != c) {
-                    break;
-                }
-                --j;
-            }
-        }
-        int i = 0;
-        if (left) {
-            for (;;) {
-                if (i == j) {
-                    return "";
-                }
-                if (s.charAt(i) != c) {
-                    break;
-                }
-                ++i;
-            }
-        }
-        return s.substring(i, j);
-    }
-
-    /** SQL {@code TRIM} function applied to binary string. */
-    public static ByteString trim(ByteString s) {
-        return trim_(s, true, true);
-    }
-
-    /** Helper for CAST. */
-    public static ByteString rtrim(ByteString s) {
-        return trim_(s, false, true);
-    }
-
-    /** SQL {@code TRIM} function applied to binary string. */
-    private static ByteString trim_(ByteString s, boolean left, boolean right) {
-        int j = s.length();
-        if (right) {
-            for (;;) {
-                if (j == 0) {
-                    return ByteString.EMPTY;
-                }
-                if (s.byteAt(j - 1) != 0) {
-                    break;
-                }
-                --j;
-            }
-        }
-        int i = 0;
-        if (left) {
-            for (;;) {
-                if (i == j) {
-                    return ByteString.EMPTY;
-                }
-                if (s.byteAt(i) != 0) {
-                    break;
-                }
-                ++i;
-            }
-        }
-        return s.substring(i, j);
-    }
-
-    /** SQL {@code OVERLAY} function. */
-    public static String overlay(String s, String r, int start) {
-        if (s == null || r == null) {
-            return null;
-        }
-        return s.substring(0, start - 1) + r + s.substring(start - 1 + r.length());
-    }
-
-    /** SQL {@code OVERLAY} function. */
-    public static String overlay(String s, String r, int start, int length) {
-        if (s == null || r == null) {
-            return null;
-        }
-        return s.substring(0, start - 1) + r + s.substring(start - 1 + length);
-    }
-
-    /** SQL {@code OVERLAY} function applied to binary strings. */
-    public static ByteString overlay(ByteString s, ByteString r, int start) {
-        if (s == null || r == null) {
-            return null;
-        }
-        return s.substring(0, start - 1).concat(r).concat(s.substring(start - 1 + r.length()));
-    }
-
-    /** SQL {@code OVERLAY} function applied to binary strings. */
-    public static ByteString overlay(ByteString s, ByteString r, int start, int length) {
-        if (s == null || r == null) {
-            return null;
-        }
-        return s.substring(0, start - 1).concat(r).concat(s.substring(start - 1 + length));
-    }
-
-    /** SQL {@code LIKE} function. */
-    public static boolean like(String s, String pattern) {
-        final String regex = Like.sqlToRegexLike(pattern, null);
-        return Pattern.matches(regex, s);
-    }
-
-    /** SQL {@code LIKE} function with escape. */
-    public static boolean like(String s, String pattern, String escape) {
-        final String regex = Like.sqlToRegexLike(pattern, escape);
-        return Pattern.matches(regex, s);
-    }
-
-    /** SQL {@code SIMILAR} function. */
-    public static boolean similar(String s, String pattern) {
-        final String regex = Like.sqlToRegexSimilar(pattern, null);
-        return Pattern.matches(regex, s);
-    }
-
-    /** SQL {@code SIMILAR} function with escape. */
-    public static boolean similar(String s, String pattern, String escape) {
-        final String regex = Like.sqlToRegexSimilar(pattern, escape);
-        return Pattern.matches(regex, s);
-    }
-
-    // =
-
-    /** SQL = operator applied to Object values (including String; neither
-     * side may be null). */
-    public static boolean eq(Object b0, Object b1) {
-        return b0.equals(b1);
-    }
-
-    /** SQL = operator applied to BigDecimal values (neither may be null). */
-    public static boolean eq(BigDecimal b0, BigDecimal b1) {
-        return b0.stripTrailingZeros().equals(b1.stripTrailingZeros());
-    }
-
-    // <>
-
-    /** SQL &lt;&gt; operator applied to Object values (including String;
-     * neither side may be null). */
-    public static boolean ne(Object b0, Object b1) {
-        return !b0.equals(b1);
-    }
-
-    /** SQL &lt;&gt; operator applied to BigDecimal values. */
-    public static boolean ne(BigDecimal b0, BigDecimal b1) {
-        return b0.compareTo(b1) != 0;
-    }
-
-    // <
-
-    /** SQL &lt; operator applied to boolean values. */
-    public static boolean lt(boolean b0, boolean b1) {
-        return compare(b0, b1) < 0;
-    }
-
-    /** SQL &lt; operator applied to String values. */
-    public static boolean lt(String b0, String b1) {
-        return b0.compareTo(b1) < 0;
-    }
-
-    /** SQL &lt; operator applied to ByteString values. */
-    public static boolean lt(ByteString b0, ByteString b1) {
-        return b0.compareTo(b1) < 0;
-    }
-
-    /** SQL &lt; operator applied to BigDecimal values. */
-    public static boolean lt(BigDecimal b0, BigDecimal b1) {
-        return b0.compareTo(b1) < 0;
-    }
-
-    // <=
-
-    /** SQL &le; operator applied to boolean values. */
-    public static boolean le(boolean b0, boolean b1) {
-        return compare(b0, b1) <= 0;
-    }
-
-    /** SQL &le; operator applied to String values. */
-    public static boolean le(String b0, String b1) {
-        return b0.compareTo(b1) <= 0;
-    }
-
-    /** SQL &le; operator applied to ByteString values. */
-    public static boolean le(ByteString b0, ByteString b1) {
-        return b0.compareTo(b1) <= 0;
-    }
-
-    /** SQL &le; operator applied to BigDecimal values. */
-    public static boolean le(BigDecimal b0, BigDecimal b1) {
-        return b0.compareTo(b1) <= 0;
-    }
-
-    // >
-
-    /** SQL &gt; operator applied to boolean values. */
-    public static boolean gt(boolean b0, boolean b1) {
-        return compare(b0, b1) > 0;
-    }
-
-    /** SQL &gt; operator applied to String values. */
-    public static boolean gt(String b0, String b1) {
-        return b0.compareTo(b1) > 0;
-    }
-
-    /** SQL &gt; operator applied to ByteString values. */
-    public static boolean gt(ByteString b0, ByteString b1) {
-        return b0.compareTo(b1) > 0;
-    }
-
-    /** SQL &gt; operator applied to BigDecimal values. */
-    public static boolean gt(BigDecimal b0, BigDecimal b1) {
-        return b0.compareTo(b1) > 0;
-    }
-
-    // >=
-
-    /** SQL &ge; operator applied to boolean values. */
-    public static boolean ge(boolean b0, boolean b1) {
-        return compare(b0, b1) >= 0;
-    }
-
-    /** SQL &ge; operator applied to String values. */
-    public static boolean ge(String b0, String b1) {
-        return b0.compareTo(b1) >= 0;
-    }
-
-    /** SQL &ge; operator applied to ByteString values. */
-    public static boolean ge(ByteString b0, ByteString b1) {
-        return b0.compareTo(b1) >= 0;
-    }
-
-    /** SQL &ge; operator applied to BigDecimal values. */
-    public static boolean ge(BigDecimal b0, BigDecimal b1) {
-        return b0.compareTo(b1) >= 0;
-    }
-
-    // +
-
-    /** SQL <code>+</code> operator applied to int values. */
-    public static int plus(int b0, int b1) {
-        return b0 + b1;
-    }
-
-    /** SQL <code>+</code> operator applied to int values; left side may be
-     * null. */
-    public static Integer plus(Integer b0, int b1) {
-        return b0 == null ? null : (b0 + b1);
-    }
-
-    /** SQL <code>+</code> operator applied to int values; right side may be
-     * null. */
-    public static Integer plus(int b0, Integer b1) {
-        return b1 == null ? null : (b0 + b1);
-    }
-
-    /** SQL <code>+</code> operator applied to nullable int values. */
-    public static Integer plus(Integer b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0 + b1);
-    }
-
-    /** SQL <code>+</code> operator applied to nullable long and int values. */
-    public static Long plus(Long b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() + b1.longValue());
-    }
-
-    /** SQL <code>+</code> operator applied to nullable int and long values. */
-    public static Long plus(Integer b0, Long b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() + b1.longValue());
-    }
-
-    /** SQL <code>+</code> operator applied to BigDecimal values. */
-    public static BigDecimal plus(BigDecimal b0, BigDecimal b1) {
-        return (b0 == null || b1 == null) ? null : b0.add(b1);
-    }
-
-    // -
-
-    /** SQL <code>-</code> operator applied to int values. */
-    public static int minus(int b0, int b1) {
-        return b0 - b1;
-    }
-
-    /** SQL <code>-</code> operator applied to int values; left side may be
-     * null. */
-    public static Integer minus(Integer b0, int b1) {
-        return b0 == null ? null : (b0 - b1);
-    }
-
-    /** SQL <code>-</code> operator applied to int values; right side may be
-     * null. */
-    public static Integer minus(int b0, Integer b1) {
-        return b1 == null ? null : (b0 - b1);
-    }
-
-    /** SQL <code>-</code> operator applied to nullable int values. */
-    public static Integer minus(Integer b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0 - b1);
-    }
-
-    /** SQL <code>-</code> operator applied to nullable long and int values. */
-    public static Long minus(Long b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() - b1.longValue());
-    }
-
-    /** SQL <code>-</code> operator applied to nullable int and long values. */
-    public static Long minus(Integer b0, Long b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() - b1.longValue());
-    }
-
-    /** SQL <code>-</code> operator applied to BigDecimal values. */
-    public static BigDecimal minus(BigDecimal b0, BigDecimal b1) {
-        return (b0 == null || b1 == null) ? null : b0.subtract(b1);
-    }
-
-    // /
-
-    /** SQL <code>/</code> operator applied to int values. */
-    public static int divide(int b0, int b1) {
-        return b0 / b1;
-    }
-
-    /** SQL <code>/</code> operator applied to int values; left side may be
-     * null. */
-    public static Integer divide(Integer b0, int b1) {
-        return b0 == null ? null : (b0 / b1);
-    }
-
-    /** SQL <code>/</code> operator applied to int values; right side may be
-     * null. */
-    public static Integer divide(int b0, Integer b1) {
-        return b1 == null ? null : (b0 / b1);
-    }
-
-    /** SQL <code>/</code> operator applied to nullable int values. */
-    public static Integer divide(Integer b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0 / b1);
-    }
-
-    /** SQL <code>/</code> operator applied to nullable long and int values. */
-    public static Long divide(Long b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() / b1.longValue());
-    }
-
-    /** SQL <code>/</code> operator applied to nullable int and long values. */
-    public static Long divide(Integer b0, Long b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() / b1.longValue());
-    }
-
-    /** SQL <code>/</code> operator applied to BigDecimal values. */
-    public static BigDecimal divide(BigDecimal b0, BigDecimal b1) {
-        // OVERRIDE POINT
-        return (b0 == null || b1 == null) ? null : b0.divide(b1, MathContext.DECIMAL64);
-    }
-
-    // *
-
-    /** SQL <code>*</code> operator applied to int values. */
-    public static int multiply(int b0, int b1) {
-        return b0 * b1;
-    }
-
-    /** SQL <code>*</code> operator applied to int values; left side may be
-     * null. */
-    public static Integer multiply(Integer b0, int b1) {
-        return b0 == null ? null : (b0 * b1);
-    }
-
-    /** SQL <code>*</code> operator applied to int values; right side may be
-     * null. */
-    public static Integer multiply(int b0, Integer b1) {
-        return b1 == null ? null : (b0 * b1);
-    }
-
-    /** SQL <code>*</code> operator applied to nullable int values. */
-    public static Integer multiply(Integer b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0 * b1);
-    }
-
-    /** SQL <code>*</code> operator applied to nullable long and int values. */
-    public static Long multiply(Long b0, Integer b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() * b1.longValue());
-    }
-
-    /** SQL <code>*</code> operator applied to nullable int and long values. */
-    public static Long multiply(Integer b0, Long b1) {
-        return (b0 == null || b1 == null) ? null : (b0.longValue() * b1.longValue());
-    }
-
-    /** SQL <code>*</code> operator applied to BigDecimal values. */
-    public static BigDecimal multiply(BigDecimal b0, BigDecimal b1) {
-        return (b0 == null || b1 == null) ? null : b0.multiply(b1);
-    }
-
-    // EXP
-
-    /** SQL <code>EXP</code> operator applied to double values. */
-    public static double exp(double b0) {
-        return Math.exp(b0);
-    }
-
-    public static double exp(long b0) {
-        return Math.exp(b0);
-    }
-
-    // POWER
-
-    /** SQL <code>POWER</code> operator applied to double values. */
-    public static double power(double b0, double b1) {
-        return Math.pow(b0, b1);
-    }
-
-    public static double power(long b0, long b1) {
-        return Math.pow(b0, b1);
-    }
-
-    public static double power(long b0, BigDecimal b1) {
-        return Math.pow(b0, b1.doubleValue());
-    }
-
-    // LN
-
-    /** SQL {@code LN(number)} function applied to double values. */
-    public static double ln(double d) {
-        return Math.log(d);
-    }
-
-    /** SQL {@code LN(number)} function applied to long values. */
-    public static double ln(long b0) {
-        return Math.log(b0);
-    }
-
-    /** SQL {@code LN(number)} function applied to BigDecimal values. */
-    public static double ln(BigDecimal d) {
-        return Math.log(d.doubleValue());
-    }
-
-    // LOG10
-
-    /** SQL <code>LOG10(numeric)</code> operator applied to double values. */
-    public static double log10(double b0) {
-        return Math.log10(b0);
-    }
-
-    /** SQL {@code LOG10(number)} function applied to long values. */
-    public static double log10(long b0) {
-        return Math.log10(b0);
-    }
-
-    /** SQL {@code LOG10(number)} function applied to BigDecimal values. */
-    public static double log10(BigDecimal d) {
-        return Math.log10(d.doubleValue());
-    }
-
-    // MOD
-
-    /** SQL <code>MOD</code> operator applied to byte values. */
-    public static byte mod(byte b0, byte b1) {
-        return (byte) (b0 % b1);
-    }
-
-    /** SQL <code>MOD</code> operator applied to short values. */
-    public static short mod(short b0, short b1) {
-        return (short) (b0 % b1);
-    }
-
-    /** SQL <code>MOD</code> operator applied to int values. */
-    public static int mod(int b0, int b1) {
-        return b0 % b1;
-    }
-
-    /** SQL <code>MOD</code> operator applied to long values. */
-    public static long mod(long b0, long b1) {
-        return b0 % b1;
-    }
-
-    // temporary
-    public static BigDecimal mod(BigDecimal b0, int b1) {
-        return mod(b0, BigDecimal.valueOf(b1));
-    }
-
-    // temporary
-    public static int mod(int b0, BigDecimal b1) {
-        return mod(b0, b1.intValue());
-    }
-
-    public static BigDecimal mod(BigDecimal b0, BigDecimal b1) {
-        final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
-        return bigDecimals[1];
-    }
-
-    // ABS
-
-    /** SQL <code>ABS</code> operator applied to byte values. */
-    public static byte abs(byte b0) {
-        return (byte) Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to short values. */
-    public static short abs(short b0) {
-        return (short) Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to int values. */
-    public static int abs(int b0) {
-        return Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to long values. */
-    public static long abs(long b0) {
-        return Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to float values. */
-    public static float abs(float b0) {
-        return Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to double values. */
-    public static double abs(double b0) {
-        return Math.abs(b0);
-    }
-
-    /** SQL <code>ABS</code> operator applied to BigDecimal values. */
-    public static BigDecimal abs(BigDecimal b0) {
-        return b0.abs();
-    }
-
-    // Helpers
-
-    /** Helper for implementing MIN. Somewhat similar to LEAST operator. */
-    public static <T extends Comparable<T>> T lesser(T b0, T b1) {
-        return b0 == null || b0.compareTo(b1) > 0 ? b1 : b0;
-    }
-
-    /** LEAST operator. */
-    public static <T extends Comparable<T>> T least(T b0, T b1) {
-        return b0 == null || b1 != null && b0.compareTo(b1) > 0 ? b1 : b0;
-    }
-
-    public static boolean greater(boolean b0, boolean b1) {
-        return b0 || b1;
-    }
-
-    public static boolean lesser(boolean b0, boolean b1) {
-        return b0 && b1;
-    }
-
-    public static byte greater(byte b0, byte b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static byte lesser(byte b0, byte b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static char greater(char b0, char b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static char lesser(char b0, char b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static short greater(short b0, short b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static short lesser(short b0, short b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static int greater(int b0, int b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static int lesser(int b0, int b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static long greater(long b0, long b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static long lesser(long b0, long b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static float greater(float b0, float b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static float lesser(float b0, float b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    public static double greater(double b0, double b1) {
-        return b0 > b1 ? b0 : b1;
-    }
-
-    public static double lesser(double b0, double b1) {
-        return b0 > b1 ? b1 : b0;
-    }
-
-    /** Helper for implementing MAX. Somewhat similar to GREATEST operator. */
-    public static <T extends Comparable<T>> T greater(T b0, T b1) {
-        return b0 == null || b0.compareTo(b1) < 0 ? b1 : b0;
-    }
-
-    /** GREATEST operator. */
-    public static <T extends Comparable<T>> T greatest(T b0, T b1) {
-        return b0 == null || b1 != null && b0.compareTo(b1) < 0 ? b1 : b0;
-    }
-
-    /** Boolean comparison. */
-    public static int compare(boolean x, boolean y) {
-        return x == y ? 0 : x ? 1 : -1;
-    }
-
-    /** CAST(FLOAT AS VARCHAR). */
-    public static String toString(float x) {
-        if (x == 0) {
-            return "0E0";
+      };
+
+  private SqlFunctions() {
+  }
+
+  /** SQL SUBSTRING(string FROM ... FOR ...) function. */
+  public static String substring(String s, int from, int for_) {
+    return s.substring(from - 1, Math.min(from - 1 + for_, s.length()));
+  }
+
+  /** SQL SUBSTRING(string FROM ...) function. */
+  public static String substring(String s, int from) {
+    return s.substring(from - 1);
+  }
+
+  /** SQL UPPER(string) function. */
+  public static String upper(String s) {
+    return s.toUpperCase();
+  }
+
+  /** SQL LOWER(string) function. */
+  public static String lower(String s) {
+    return s.toLowerCase();
+  }
+
+  /** SQL INITCAP(string) function. */
+  public static String initcap(String s) {
+    // Assumes Alpha as [A-Za-z0-9]
+    // white space is treated as everything else.
+    final int len = s.length();
+    boolean start = true;
+    final StringBuilder newS = new StringBuilder();
+
+    for (int i = 0; i < len; i++) {
+      char curCh = s.charAt(i);
+      final int c = (int) curCh;
+      if (start) {  // curCh is whitespace or first character of word.
+        if (c > 47 && c < 58) { // 0-9
+          start = false;
+        } else if (c > 64 && c < 91) {  // A-Z
+          start = false;
+        } else if (c > 96 && c < 123) {  // a-z
+          start = false;
+          curCh = (char) (c - 32); // Uppercase this character
         }
-        BigDecimal bigDecimal = new BigDecimal(x, MathContext.DECIMAL32).stripTrailingZeros();
-        final String s = bigDecimal.toString();
-        return s.replaceAll("0*E", "E").replace("E+", "E");
-    }
-
-    /** CAST(DOUBLE AS VARCHAR). */
-    public static String toString(double x) {
-        if (x == 0) {
-            return "0E0";
+        // else {} whitespace
+      } else {  // Inside of a word or white space after end of word.
+        if (c > 47 && c < 58) { // 0-9
+          // noop
+        } else if (c > 64 && c < 91) {  // A-Z
+          curCh = (char) (c + 32); // Lowercase this character
+        } else if (c > 96 && c < 123) {  // a-z
+          // noop
+        } else { // whitespace
+          start = true;
         }
-        BigDecimal bigDecimal = new BigDecimal(x, MathContext.DECIMAL64).stripTrailingZeros();
-        final String s = bigDecimal.toString();
-        return s.replaceAll("0*E", "E").replace("E+", "E");
-    }
-
-    /** CAST(DECIMAL AS VARCHAR). */
-    public static String toString(BigDecimal x) {
-        final String s = x.toString();
-        if (s.startsWith("0")) {
-            // we want ".1" not "0.1"
-            return s.substring(1);
-        } else if (s.startsWith("-0")) {
-            // we want "-.1" not "-0.1"
-            return "-" + s.substring(2);
-        } else {
-            return s;
+      }
+      newS.append(curCh);
+    } // for each character in s
+    return newS.toString();
+  }
+
+  /** SQL CHARACTER_LENGTH(string) function. */
+  public static int charLength(String s) {
+    return s.length();
+  }
+
+  /** SQL {@code string || string} operator. */
+  public static String concat(String s0, String s1) {
+    return s0 + s1;
+  }
+
+  /** SQL {@code binary || binary} operator. */
+  public static ByteString concat(ByteString s0, ByteString s1) {
+    return s0.concat(s1);
+  }
+
+  /** SQL {@code RTRIM} function applied to string. */
+  public static String rtrim(String s) {
+    return trim_(s, false, true, ' ');
+  }
+
+  /** SQL {@code LTRIM} function. */
+  public static String ltrim(String s) {
+    return trim_(s, true, false, ' ');
+  }
+
+  /** SQL {@code TRIM(... seek FROM s)} function. */
+  public static String trim(boolean leading, boolean trailing, String seek,
+      String s) {
+    return trim_(s, leading, trailing, seek.charAt(0));
+  }
+
+  /** SQL {@code TRIM} function. */
+  private static String trim_(String s, boolean left, boolean right, char c) {
+    int j = s.length();
+    if (right) {
+      for (;;) {
+        if (j == 0) {
+          return "";
         }
-    }
-
-    /** CAST(BOOLEAN AS VARCHAR). */
-    public static String toString(boolean x) {
-        // Boolean.toString returns lower case -- no good.
-        return x ? "TRUE" : "FALSE";
-    }
-
-    @NonDeterministic
-    private static Object cannotConvert(Object o, Class toType) {
-        throw new RuntimeException("Cannot convert " + o + " to " + toType);
-    }
-
-    /** CAST(VARCHAR AS BOOLEAN). */
-    public static boolean toBoolean(String s) {
-        s = trim_(s, true, true, ' ');
-        if (s.equalsIgnoreCase("TRUE")) {
-            return true;
-        } else if (s.equalsIgnoreCase("FALSE")) {
-            return false;
-        } else {
-            throw new RuntimeException("Invalid character for cast");
+        if (s.charAt(j - 1) != c) {
+          break;
         }
-    }
-
-    public static boolean toBoolean(Number number) {
-        return !number.equals(0);
-    }
-
-    public static boolean toBoolean(Object o) {
-        return o instanceof Boolean ? (Boolean) o : o instanceof Number ? toBoolean((Number) o) : o instanceof String ? toBoolean((String) o) : (Boolean) cannotConvert(o, boolean.class);
-    }
-
-    // Don't need parseByte etc. - Byte.parseByte is sufficient.
-
-    public static byte toByte(Object o) {
-        return o instanceof Byte ? (Byte) o : o instanceof Number ? toByte((Number) o) : Byte.parseByte(o.toString());
-    }
-
-    public static byte toByte(Number number) {
-        return number.byteValue();
-    }
-
-    public static char toChar(String s) {
-        return s.charAt(0);
-    }
-
-    public static Character toCharBoxed(String s) {
-        return s.charAt(0);
-    }
-
-    public static short toShort(String s) {
-        return Short.parseShort(s.trim());
-    }
-
-    public static short toShort(Number number) {
-        return number.shortValue();
-    }
-
-    public static short toShort(Object o) {
-        return o instanceof Short ? (Short) o : o instanceof Number ? toShort((Number) o) : o instanceof String ? toShort((String) o) : (Short) cannotConvert(o, short.class);
-    }
-
-    public static int toInt(java.util.Date v) {
-        return toInt(v, LOCAL_TZ);
-    }
-
-    public static int toInt(java.util.Date v, TimeZone timeZone) {
-        return (int) (toLong(v, timeZone) / DateTimeUtil.MILLIS_PER_DAY);
-    }
-
-    public static Integer toIntOptional(java.util.Date v) {
-        return v == null ? null : toInt(v);
-    }
-
-    public static Integer toIntOptional(java.util.Date v, TimeZone timeZone) {
-        return v == null ? null : toInt(v, timeZone);
-    }
-
-    public static long toLong(Date v) {
-        return toLong(v, LOCAL_TZ);
-    }
-
-    public static int toInt(java.sql.Time v) {
-        return (int) (toLong(v) % DateTimeUtil.MILLIS_PER_DAY);
-    }
-
-    public static Integer toIntOptional(java.sql.Time v) {
-        return v == null ? null : toInt(v);
-    }
-
-    public static int toInt(String s) {
-        return Integer.parseInt(s.trim());
-    }
-
-    public static int toInt(Number number) {
-        return number.intValue();
-    }
-
-    public static int toInt(Object o) {
-        return o instanceof Integer ? (Integer) o : o instanceof Number ? toInt((Number) o) : o instanceof String ? toInt((String) o) : (Integer) cannotConvert(o, int.class);
-    }
-
-    public static long toLong(Timestamp v) {
-        return toLong(v, LOCAL_TZ);
-    }
-
-    // mainly intended for java.sql.Timestamp but works for other dates also
-    public static long toLong(java.util.Date v, TimeZone timeZone) {
-        final long time = v.getTime();
-        return time + timeZone.getOffset(time);
-    }
-
-    // mainly intended for java.sql.Timestamp but works for other dates also
-    public static Long toLongOptional(java.util.Date v) {
-        return v == null ? null : toLong(v, LOCAL_TZ);
-    }
-
-    public static Long toLongOptional(Timestamp v, TimeZone timeZone) {
-        if (v == null) {
-            return null;
+        --j;
+      }
+    }
+    int i = 0;
+    if (left) {
+      for (;;) {
+        if (i == j) {
+          return "";
         }
-        return toLong(v, LOCAL_TZ);
-    }
-
-    public static long toLong(String s) {
-        if (s.startsWith("199") && s.contains(":")) {
-            return Timestamp.valueOf(s).getTime();
+        if (s.charAt(i) != c) {
+          break;
         }
-        return Long.parseLong(s.trim());
-    }
-
-    public static long toLong(Number number) {
-        return number.longValue();
-    }
-
-    public static long toLong(Object o) {
-        return o instanceof Long ? (Long) o : o instanceof Number ? toLong((Number) o) : o instanceof String ? toLong((String) o) : (Long) cannotConvert(o, long.class);
-    }
-
-    public static float toFloat(String s) {
-        return Float.parseFloat(s.trim());
-    }
-
-    public static float toFloat(Number number) {
-        return number.floatValue();
-    }
-
-    public static float toFloat(Object o) {
-        return o instanceof Float ? (Float) o : o instanceof Number ? toFloat((Number) o) : o instanceof String ? toFloat((String) o) : (Float) cannotConvert(o, float.class);
-    }
-
-    public static double toDouble(String s) {
-        return Double.parseDouble(s.trim());
-    }
-
-    public static double toDouble(Number number) {
-        return number.doubleValue();
-    }
-
-    public static double toDouble(Object o) {
-        return o instanceof Double ? (Double) o : o instanceof Number ? toDouble((Number) o) : o instanceof String ? toDouble((String) o) : (Double) cannotConvert(o, double.class);
-    }
-
-    public static BigDecimal toBigDecimal(String s) {
-        return new BigDecimal(s.trim());
-    }
-
-    public static BigDecimal toBigDecimal(Number number) {
-        // There are some values of "long" that cannot be represented as "double".
-        // Not so "int". If it isn't a long, go straight to double.
-        return number instanceof BigDecimal ? (BigDecimal) number : number instanceof BigInteger ? new BigDecimal((BigInteger) number) : number instanceof Long ? new BigDecimal(number.longValue()) : new BigDecimal(number.doubleValue());
-    }
-
-    public static BigDecimal toBigDecimal(Object o) {
-        return o instanceof Number ? toBigDecimal((Number) o) : toBigDecimal(o.toString());
-    }
-
-    // Don't need shortValueOf etc. - Short.valueOf is sufficient.
-
-    /** Helper for CAST(... AS VARCHAR(maxLength)). */
-    public static String truncate(String s, int maxLength) {
-        return s == null ? null : s.length() > maxLength ? s.substring(0, maxLength) : s;
-    }
-
-    /** Helper for CAST(... AS VARBINARY(maxLength)). */
-    public static ByteString truncate(ByteString s, int maxLength) {
-        return s == null ? null : s.length() > maxLength ? s.substring(0, maxLength) : s;
-    }
-
-    /** SQL {@code POSITION(seek IN string)} function. */
-    public static int position(String seek, String s) {
-        return s.indexOf(seek) + 1;
-    }
-
-    /** SQL {@code POSITION(seek IN string)} function. */
-    public static int position(ByteString seek, ByteString s) {
-        return s.indexOf(seek) + 1;
-    }
-
-    /** Cheap, unsafe, long power. power(2, 3) returns 8. */
-    public static long powerX(long a, long b) {
-        long x = 1;
-        while (b > 0) {
-            x *= a;
-            --b;
-        }
-        return x;
-    }
-
-    /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
-    public static long round(long v, long x) {
-        return truncate(v + x / 2, x);
-    }
-
-    /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
-    public static long truncate(long v, long x) {
-        long remainder = v % x;
-        if (remainder < 0) {
-            remainder += x;
+        ++i;
+      }
+    }
+    return s.substring(i, j);
+  }
+
+  /** SQL {@code TRIM} function applied to binary string. */
+  public static ByteString trim(ByteString s) {
+    return trim_(s, true, true);
+  }
+
+  /** Helper for CAST. */
+  public static ByteString rtrim(ByteString s) {
+    return trim_(s, false, true);
+  }
+
+  /** SQL {@code TRIM} function applied to binary string. */
+  private static ByteString trim_(ByteString s, boolean left, boolean right) {
+    int j = s.length();
+    if (right) {
+      for (;;) {
+        if (j == 0) {
+          return ByteString.EMPTY;
         }
-        return v - remainder;
-    }
-
-    /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
-    public static int round(int v, int x) {
-        return truncate(v + x / 2, x);
-    }
-
-    /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
-    public static int truncate(int v, int x) {
-        int remainder = v % x;
-        if (remainder < 0) {
-            remainder += x;
-        }
-        return v - remainder;
-    }
-
-    /** Helper for CAST({timestamp} AS VARCHAR(n)). */
-    public static String unixTimestampToString(long timestamp) {
-        final StringBuilder buf = new StringBuilder(17);
-        int date = (int) (timestamp / DateTimeUtil.MILLIS_PER_DAY);
-        int time = (int) (timestamp % DateTimeUtil.MILLIS_PER_DAY);
-        if (time < 0) {
-            --date;
-            time += DateTimeUtil.MILLIS_PER_DAY;
+        if (s.byteAt(j - 1) != 0) {
+          break;
         }
-        unixDateToString(buf, date);
-        buf.append(' ');
-        unixTimeToString(buf, time);
-        return buf.toString();
-    }
-
-    /** Helper for CAST({timestamp} AS VARCHAR(n)). */
-    public static String unixTimeToString(int time) {
-        final StringBuilder buf = new StringBuilder(8);
-        unixTimeToString(buf, time);
-        return buf.toString();
-    }
-
-    private static void unixTimeToString(StringBuilder buf, int time) {
-        int h = time / 3600000;
-        int time2 = time % 3600000;
-        int m = time2 / 60000;
-        int time3 = time2 % 60000;
-        int s = time3 / 1000;
-        int ms = time3 % 1000;
-        int2(buf, h);
-        buf.append(':');
-        int2(buf, m);
-        buf.append(':');
-        int2(buf, s);
-    }
-
-    /** SQL {@code CURRENT_TIMESTAMP} function. */
-    @NonDeterministic
-    public static long currentTimestamp(DataContext root) {
-        // Cast required for JDK 1.6.
-        return (Long) DataContext.Variable.CURRENT_TIMESTAMP.get(root);
-    }
-
-    /** SQL {@code CURRENT_TIME} function. */
-    @NonDeterministic
-    public static int currentTime(DataContext root) {
-        int time = (int) (currentTimestamp(root) % DateTimeUtil.MILLIS_PER_DAY);
-        if (time < 0) {
-            time += DateTimeUtil.MILLIS_PER_DAY;
+        --j;
+      }
+    }
+    int i = 0;
+    if (left) {
+      for (;;) {
+        if (i == j) {
+          return ByteString.EMPTY;
         }
-        return time;
-    }
-
-    /** SQL {@code CURRENT_DATE} function. */
-    @NonDeterministic
-    public static int currentDate(DataContext root) {
-        final long timestamp = currentTimestamp(root);
-        int date = (int) (timestamp / DateTimeUtil.MILLIS_PER_DAY);
-        final int time = (int) (timestamp % DateTimeUtil.MILLIS_PER_DAY);
-        if (time < 0) {
-            --date;
+        if (s.byteAt(i) != 0) {
+          break;
         }
-        return date;
-    }
-
-    /** SQL {@code LOCAL_TIMESTAMP} function. */
-    @NonDeterministic
-    public static long localTimestamp(DataContext root) {
-        // Cast required for JDK 1.6.
-        return (Long) DataContext.Variable.LOCAL_TIMESTAMP.get(root);
-    }
-
-    /** SQL {@code LOCAL_TIME} function. */
-    @NonDeterministic
-    public static int localTime(DataContext root) {
-        return (int) (localTimestamp(root) % DateTimeUtil.MILLIS_PER_DAY);
-    }
-
-    private static void int2(StringBuilder buf, int i) {
-        buf.append((char) ('0' + (i / 10) % 10));
-        buf.append((char) ('0' + i % 10));
-    }
-
-    private static void int4(StringBuilder buf, int i) {
-        buf.append((char) ('0' + (i / 1000) % 10));
-        buf.append((char) ('0' + (i / 100) % 10));
-        buf.append((char) ('0' + (i / 10) % 10));
-        buf.append((char) ('0' + i % 10));
-    }
-
-    public static int dateStringToUnixDate(String s) {
-        int hyphen1 = s.indexOf('-');
-        int y;
-        int m;
-        int d;
-        if (hyphen1 < 0) {
-            y = Integer.parseInt(s.trim());
-            m = 1;
-            d = 1;
-        } else {
-            y = Integer.parseInt(s.substring(0, hyphen1).trim());
-            final int hyphen2 = s.indexOf('-', hyphen1 + 1);
-            if (hyphen2 < 0) {
-                m = Integer.parseInt(s.substring(hyphen1 + 1).trim());
-                d = 1;
-            } else {
-                m = Integer.parseInt(s.substring(hyphen1 + 1, hyphen2).trim());
-                d = Integer.parseInt(s.substring(hyphen2 + 1).trim());
-            }
-        }
-        return ymdToUnixDate(y, m, d);
-    }
-
-    public static int timeStringToUnixDate(String v) {
-        return timeStringToUnixDate(v, 0);
-    }
-
-    public static int timeStringToUnixDate(String v, int start) {
-        final int colon1 = v.indexOf(':', start);
-        int hour;
-        int minute;
-        int second;
-        int milli;
-        if (colon1 < 0) {
-            hour = Integer.parseInt(v.trim());
-            minute = 1;
-            second = 1;
-            milli = 0;
-        } else {
-            hour = Integer.parseInt(v.substring(start, colon1).trim());
-            final int colon2 = v.indexOf(':', colon1 + 1);
-            if (colon2 < 0) {
-                minute = Integer.parseInt(v.substring(colon1 + 1).trim());
-                second = 1;
-                milli = 0;
-            } else {
-                minute = Integer.parseInt(v.substring(colon1 + 1, colon2).trim());
-                int dot = v.indexOf('.', colon2);
-                if (dot < 0) {
-                    second = Integer.parseInt(v.substring(colon2 + 1).trim());
-                    milli = 0;
-                } else {
-                    second = Integer.parseInt(v.substring(colon2 + 1, dot).trim());
-                    milli = Integer.parseInt(v.substring(dot + 1).trim());
-                }
-            }
-        }
-        return hour * (int) DateTimeUtil.MILLIS_PER_HOUR + minute * (int) DateTimeUtil.MILLIS_PER_MINUTE + second * (int) DateTimeUtil.MILLIS_PER_SECOND + milli;
-    }
-
-    public static long timestampStringToUnixDate(String s) {
-        final long d;
-        final long t;
-        s = s.trim();
-        int space = s.indexOf(' ');
-        if (space >= 0) {
-            d = dateStringToUnixDate(s.substring(0, space));
-            t = timeStringToUnixDate(s, space + 1);
+        ++i;
+      }
+    }
+    return s.substring(i, j);
+  }
+
+  /** SQL {@code OVERLAY} function. */
+  public static String overlay(String s, String r, int start) {
+    if (s == null || r == null) {
+      return null;
+    }
+    return s.substring(0, start - 1)
+        + r
+        + s.substring(start - 1 + r.length());
+  }
+
+  /** SQL {@code OVERLAY} function. */
+  public static String overlay(String s, String r, int start, int length) {
+    if (s == null || r == null) {
+      return null;
+    }
+    return s.substring(0, start - 1)
+        + r
+        + s.substring(start - 1 + length);
+  }
+
+  /** SQL {@code OVERLAY} function applied to binary strings. */
+  public static ByteString overlay(ByteString s, ByteString r, int start) {
+    if (s == null || r == null) {
+      return null;
+    }
+    return s.substring(0, start - 1)
+           .concat(r)
+           .concat(s.substring(start - 1 + r.length()));
+  }
+
+  /** SQL {@code OVERLAY} function applied to binary strings. */
+  public static ByteString overlay(ByteString s, ByteString r, int start,
+      int length) {
+    if (s == null || r == null) {
+      return null;
+    }
+    return s.substring(0, start - 1)
+           .concat(r)
+           .concat(s.substring(start - 1 + length));
+  }
+
+  /** SQL {@code LIKE} function. */
+  public static boolean like(String s, String pattern) {
+    final String regex = Like.sqlToRegexLike(pattern, null);
+    return Pattern.matches(regex, s);
+  }
+
+  /** SQL {@code LIKE} function with escape. */
+  public static boolean like(String s, String pattern, String escape) {
+    final String regex = Like.sqlToRegexLike(pattern, escape);
+    return Pattern.matches(regex, s);
+  }
+
+  /** SQL {@code SIMILAR} function. */
+  public static boolean similar(String s, String pattern) {
+    final String regex = Like.sqlToRegexSimilar(pattern, null);
+    return Pattern.matches(regex, s);
+  }
+
+  /** SQL {@code SIMILAR} function with escape. */
+  public static boolean similar(String s, String pattern, String escape) {
+    final String regex = Like.sqlToRegexSimilar(pattern, escape);
+    return Pattern.matches(regex, s);
+  }
+
+  // =
+
+  /** SQL = operator applied to Object values (including String; neither
+   * side may be null). */
+  public static boolean eq(Object b0, Object b1) {
+    return b0.equals(b1);
+  }
+
+  /** SQL = operator applied to BigDecimal values (neither may be null). */
+  public static boolean eq(BigDecimal b0, BigDecimal b1) {
+    return b0.stripTrailingZeros().equals(b1.stripTrailingZeros());
+  }
+
+  // <>
+
+  /** SQL &lt;&gt; operator applied to Object values (including String;
+   * neither side may be null). */
+  public static boolean ne(Object b0, Object b1) {
+    return !b0.equals(b1);
+  }
+
+  /** SQL &lt;&gt; operator applied to BigDecimal values. */
+  public static boolean ne(BigDecimal b0, BigDecimal b1) {
+    return b0.compareTo(b1) != 0;
+  }
+
+  // <
+
+  /** SQL &lt; operator applied to boolean values. */
+  public static boolean lt(boolean b0, boolean b1) {
+    return compare(b0, b1) < 0;
+  }
+
+  /** SQL &lt; operator applied to String values. */
+  public static boolean lt(String b0, String b1) {
+    return b0.compareTo(b1) < 0;
+  }
+
+  /** SQL &lt; operator applied to ByteString values. */
+  public static boolean lt(ByteString b0, ByteString b1) {
+    return b0.compareTo(b1) < 0;
+  }
+
+  /** SQL &lt; operator applied to BigDecimal values. */
+  public static boolean lt(BigDecimal b0, BigDecimal b1) {
+    return b0.compareTo(b1) < 0;
+  }
+
+  // <=
+
+  /** SQL &le; operator applied to boolean values. */
+  public static boolean le(boolean b0, boolean b1) {
+    return compare(b0, b1) <= 0;
+  }
+
+  /** SQL &le; operator applied to String values. */
+  public static boolean le(String b0, String b1) {
+    return b0.compareTo(b1) <= 0;
+  }
+
+  /** SQL &le; operator applied to ByteString values. */
+  public static boolean le(ByteString b0, ByteString b1) {
+    return b0.compareTo(b1) <= 0;
+  }
+
+  /** SQL &le; operator applied to BigDecimal values. */
+  public static boolean le(BigDecimal b0, BigDecimal b1) {
+    return b0.compareTo(b1) <= 0;
+  }
+
+  // >
+
+  /** SQL &gt; operator applied to boolean values. */
+  public static boolean gt(boolean b0, boolean b1) {
+    return compare(b0, b1) > 0;
+  }
+
+  /** SQL &gt; operator applied to String values. */
+  public static boolean gt(String b0, String b1) {
+    return b0.compareTo(b1) > 0;
+  }
+
+  /** SQL &gt; operator applied to ByteString values. */
+  public static boolean gt(ByteString b0, ByteString b1) {
+    return b0.compareTo(b1) > 0;
+  }
+
+  /** SQL &gt; operator applied to BigDecimal values. */
+  public static boolean gt(BigDecimal b0, BigDecimal b1) {
+    return b0.compareTo(b1) > 0;
+  }
+
+  // >=
+
+  /** SQL &ge; operator applied to boolean values. */
+  public static boolean ge(boolean b0, boolean b1) {
+    return compare(b0, b1) >= 0;
+  }
+
+  /** SQL &ge; operator applied to String values. */
+  public static boolean ge(String b0, String b1) {
+    return b0.compareTo(b1) >= 0;
+  }
+
+  /** SQL &ge; operator applied to ByteString values. */
+  public static boolean ge(ByteString b0, ByteString b1) {
+    return b0.compareTo(b1) >= 0;
+  }
+
+  /** SQL &ge; operator applied to BigDecimal values. */
+  public static boolean ge(BigDecimal b0, BigDecimal b1) {
+    return b0.compareTo(b1) >= 0;
+  }
+
+  // +
+
+  /** SQL <code>+</code> operator applied to int values. */
+  public static int plus(int b0, int b1) {
+    return b0 + b1;
+  }
+
+  /** SQL <code>+</code> operator applied to int values; left side may be
+   * null. */
+  public static Integer plus(Integer b0, int b1) {
+    return b0 == null ? null : (b0 + b1);
+  }
+
+  /** SQL <code>+</code> operator applied to int values; right side may be
+   * null. */
+  public static Integer plus(int b0, Integer b1) {
+    return b1 == null ? null : (b0 + b1);
+  }
+
+  /** SQL <code>+</code> operator applied to nullable int values. */
+  public static Integer plus(Integer b0, Integer b1) {
+    return (b0 == null || b1 == null) ? null : (b0 + b1);
+  }
+
+  /** SQL <code>+</code> operator applied to nullable long and int values. */
+  public static Long plus(Long b0, Integer b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() + b1.longValue());
+  }
+
+  /** SQL <code>+</code> operator applied to nullable int and long values. */
+  public static Long plus(Integer b0, Long b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() + b1.longValue());
+  }
+
+  /** SQL <code>+</code> operator applied to BigDecimal values. */
+  public static BigDecimal plus(BigDecimal b0, BigDecimal b1) {
+    return (b0 == null || b1 == null) ? null : b0.add(b1);
+  }
+
+  // -
+
+  /** SQL <code>-</code> operator applied to int values. */
+  public static int minus(int b0, int b1) {
+    return b0 - b1;
+  }
+
+  /** SQL <code>-</code> operator applied to int values; left side may be
+   * null. */
+  public static Integer minus(Integer b0, int b1) {
+    return b0 == null ? null : (b0 - b1);
+  }
+
+  /** SQL <code>-</code> operator applied to int values; right side may be
+   * null. */
+  public static Integer minus(int b0, Integer b1) {
+    return b1 == null ? null : (b0 - b1);
+  }
+
+  /** SQL <code>-</code> operator applied to nullable int values. */
+  public static Integer minus(Integer b0, Integer b1) {
+    return (b0 == null || b1 == null) ? null : (b0 - b1);
+  }
+
+  /** SQL <code>-</code> operator applied to nullable long and int values. */
+  public static Long minus(Long b0, Integer b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() - b1.longValue());
+  }
+
+  /** SQL <code>-</code> operator applied to nullable int and long values. */
+  public static Long minus(Integer b0, Long b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() - b1.longValue());
+  }
+
+  /** SQL <code>-</code> operator applied to BigDecimal values. */
+  public static BigDecimal minus(BigDecimal b0, BigDecimal b1) {
+    return (b0 == null || b1 == null) ? null : b0.subtract(b1);
+  }
+
+  // /
+
+  /** SQL <code>/</code> operator applied to int values. */
+  public static int divide(int b0, int b1) {
+    return b0 / b1;
+  }
+
+  /** SQL <code>/</code> operator applied to int values; left side may be
+   * null. */
+  public static Integer divide(Integer b0, int b1) {
+    return b0 == null ? null : (b0 / b1);
+  }
+
+  /** SQL <code>/</code> operator applied to int values; right side may be
+   * null. */
+  public static Integer divide(int b0, Integer b1) {
+    return b1 == null ? null : (b0 / b1);
+  }
+
+  /** SQL <code>/</code> operator applied to nullable int values. */
+  public static Integer divide(Integer b0, Integer b1) {
+    return (b0 == null || b1 == null) ? null : (b0 / b1);
+  }
+
+  /** SQL <code>/</code> operator applied to nullable long and int values. */
+  public static Long divide(Long b0, Integer b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() / b1.longValue());
+  }
+
+  /** SQL <code>/</code> operator applied to nullable int and long values. */
+  public static Long divide(Integer b0, Long b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() / b1.longValue());
+  }
+
+  /** SQL <code>/</code> operator applied to BigDecimal values. */
+  public static BigDecimal divide(BigDecimal b0, BigDecimal b1) {
+    // OVERRIDE POINT
+    return (b0 == null || b1 == null) ? null : b0.divide(b1, MathContext.DECIMAL64);
+  }
+
+  // *
+
+  /** SQL <code>*</code> operator applied to int values. */
+  public static int multiply(int b0, int b1) {
+    return b0 * b1;
+  }
+
+  /** SQL <code>*</code> operator applied to int values; left side may be
+   * null. */
+  public static Integer multiply(Integer b0, int b1) {
+    return b0 == null ? null : (b0 * b1);
+  }
+
+  /** SQL <code>*</code> operator applied to int values; right side may be
+   * null. */
+  public static Integer multiply(int b0, Integer b1) {
+    return b1 == null ? null : (b0 * b1);
+  }
+
+  /** SQL <code>*</code> operator applied to nullable int values. */
+  public static Integer multiply(Integer b0, Integer b1) {
+    return (b0 == null || b1 == null) ? null : (b0 * b1);
+  }
+
+  /** SQL <code>*</code> operator applied to nullable long and int values. */
+  public static Long multiply(Long b0, Integer b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() * b1.longValue());
+  }
+
+  /** SQL <code>*</code> operator applied to nullable int and long values. */
+  public static Long multiply(Integer b0, Long b1) {
+    return (b0 == null || b1 == null)
+        ? null
+        : (b0.longValue() * b1.longValue());
+  }
+
+  /** SQL <code>*</code> operator applied to BigDecimal values. */
+  public static BigDecimal multiply(BigDecimal b0, BigDecimal b1) {
+    return (b0 == null || b1 == null) ? null : b0.multiply(b1);
+  }
+
+  // EXP
+
+  /** SQL <code>EXP</code> operator applied to double values. */
+  public static double exp(double b0) {
+    return Math.exp(b0);
+  }
+
+  public static double exp(long b0) {
+    return Math.exp(b0);
+  }
+
+  // POWER
+
+  /** SQL <code>POWER</code> operator applied to double values. */
+  public static double power(double b0, double b1) {
+    return Math.pow(b0, b1);
+  }
+
+  public static double power(long b0, long b1) {
+    return Math.pow(b0, b1);
+  }
+
+  public static double power(long b0, BigDecimal b1) {
+    return Math.pow(b0, b1.doubleValue());
+  }
+
+  // LN
+
+  /** SQL {@code LN(number)} function applied to double values. */
+  public static double ln(double d) {
+    return Math.log(d);
+  }
+
+  /** SQL {@code LN(number)} function applied to long values. */
+  public static double ln(long b0) {
+    return Math.log(b0);
+  }
+
+  /** SQL {@code LN(number)} function applied to BigDecimal values. */
+  public static double ln(BigDecimal d) {
+    return Math.log(d.doubleValue());
+  }
+
+  // LOG10
+
+  /** SQL <code>LOG10(numeric)</code> operator applied to double values. */
+  public static double log10(double b0) {
+    return Math.log10(b0);
+  }
+
+  /** SQL {@code LOG10(number)} function applied to long values. */
+  public static double log10(long b0) {
+    return Math.log10(b0);
+  }
+
+  /** SQL {@code LOG10(number)} function applied to BigDecimal values. */
+  public static double log10(BigDecimal d) {
+    return Math.log10(d.doubleValue());
+  }
+
+  // MOD
+
+  /** SQL <code>MOD</code> operator applied to byte values. */
+  public static byte mod(byte b0, byte b1) {
+    return (byte) (b0 % b1);
+  }
+
+  /** SQL <code>MOD</code> operator applied to short values. */
+  public static short mod(short b0, short b1) {
+    return (short) (b0 % b1);
+  }
+
+  /** SQL <code>MOD</code> operator applied to int values. */
+  public static int mod(int b0, int b1) {
+    return b0 % b1;
+  }
+
+  /** SQL <code>MOD</code> operator applied to long values. */
+  public static long mod(long b0, long b1) {
+    return b0 % b1;
+  }
+
+  // temporary
+  public static BigDecimal mod(BigDecimal b0, int b1) {
+    return mod(b0, BigDecimal.valueOf(b1));
+  }
+
+  // temporary
+  public static int mod(int b0, BigDecimal b1) {
+    return mod(b0, b1.intValue());
+  }
+
+  public static BigDecimal mod(BigDecimal b0, BigDecimal b1) {
+    final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
+    return bigDecimals[1];
+  }
+
+  // ABS
+
+  /** SQL <code>ABS</code> operator applied to byte values. */
+  public static byte abs(byte b0) {
+    return (byte) Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to short values. */
+  public static short abs(short b0) {
+    return (short) Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to int values. */
+  public static int abs(int b0) {
+    return Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to long values. */
+  public static long abs(long b0) {
+    return Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to float values. */
+  public static float abs(float b0) {
+    return Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to double values. */
+  public static double abs(double b0) {
+    return Math.abs(b0);
+  }
+
+  /** SQL <code>ABS</code> operator applied to BigDecimal values. */
+  public static BigDecimal abs(BigDecimal b0) {
+    return b0.abs();
+  }
+
+  // Helpers
+
+  /** Helper for implementing MIN. Somewhat similar to LEAST operator. */
+  public static <T extends Comparable<T>> T lesser(T b0, T b1) {
+    return b0 == null || b0.compareTo(b1) > 0 ? b1 : b0;
+  }
+
+  /** LEAST operator. */
+  public static <T extends Comparable<T>> T least(T b0, T b1) {
+    return b0 == null || b1 != null && b0.compareTo(b1) > 0 ? b1 : b0;
+  }
+
+  public static boolean greater(boolean b0, boolean b1) {
+    return b0 || b1;
+  }
+
+  public static boolean lesser(boolean b0, boolean b1) {
+    return b0 && b1;
+  }
+
+  public static byte greater(byte b0, byte b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static byte lesser(byte b0, byte b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static char greater(char b0, char b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static char lesser(char b0, char b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static short greater(short b0, short b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static short lesser(short b0, short b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static int greater(int b0, int b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static int lesser(int b0, int b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static long greater(long b0, long b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static long lesser(long b0, long b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static float greater(float b0, float b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static float lesser(float b0, float b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  public static double greater(double b0, double b1) {
+    return b0 > b1 ? b0 : b1;
+  }
+
+  public static double lesser(double b0, double b1) {
+    return b0 > b1 ? b1 : b0;
+  }
+
+  /** Helper for implementing MAX. Somewhat similar to GREATEST operator. */
+  public static <T extends Comparable<T>> T greater(T b0, T b1) {
+    return b0 == null || b0.compareTo(b1) < 0 ? b1 : b0;
+  }
+
+  /** GREATEST operator. */
+  public static <T extends Comparable<T>> T greatest(T b0, T b1) {
+    return b0 == null || b1 != null && b0.compareTo(b1) < 0 ? b1 : b0;
+  }
+
+  /** Boolean comparison. */
+  public static int compare(boolean x, boolean y) {
+    return x == y ? 0 : x ? 1 : -1;
+  }
+
+  /** CAST(FLOAT AS VARCHAR). */
+  public static String toString(float x) {
+    if (x == 0) {
+      return "0E0";
+    }
+    BigDecimal bigDecimal =
+        new BigDecimal(x, MathContext.DECIMAL32).stripTrailingZeros();
+    final String s = bigDecimal.toString();
+    return s.replaceAll("0*E", "E").replace("E+", "E");
+  }
+
+  /** CAST(DOUBLE AS VARCHAR). */
+  public static String toString(double x) {
+    if (x == 0) {
+      return "0E0";
+    }
+    BigDecimal bigDecimal =
+        new BigDecimal(x, MathContext.DECIMAL64).stripTrailingZeros();
+    final String s = bigDecimal.toString();
+    return s.replaceAll("0*E", "E").replace("E+", "E");
+  }
+
+  /** CAST(DECIMAL AS VARCHAR). */
+  public static String toString(BigDecimal x) {
+    final String s = x.toString();
+    if (s.startsWith("0")) {
+      // we want ".1" not "0.1"
+      return s.substring(1);
+    } else if (s.startsWith("-0")) {
+      // we want "-.1" not "-0.1"
+      return "-" + s.substring(2);
+    } else {
+      return s;
+    }
+  }
+
+  /** CAST(BOOLEAN AS VARCHAR). */
+  public static String toString(boolean x) {
+    // Boolean.toString returns lower case -- no good.
+    return x ? "TRUE" : "FALSE";
+  }
+
+  @NonDeterministic
+  private static Object cannotConvert(Object o, Class toType) {
+    throw new RuntimeException("Cannot convert " + o + " to " + toType);
+  }
+
+  /** CAST(VARCHAR AS BOOLEAN). */
+  public static boolean toBoolean(String s) {
+    s = trim_(s, true, true, ' ');
+    if (s.equalsIgnoreCase("TRUE")) {
+      return true;
+    } else if (s.equalsIgnoreCase("FALSE")) {
+      return false;
+    } else {
+      throw new RuntimeException("Invalid character for cast");
+    }
+  }
+
+  public static boolean toBoolean(Number number) {
+    return !number.equals(0);
+  }
+
+  public static boolean toBoolean(Object o) {
+    return o instanceof Boolean ? (Boolean) o
+        : o instanceof Number ? toBoolean((Number) o)
+        : o instanceof String ? toBoolean((String) o)
+        : (Boolean) cannotConvert(o, boolean.class);
+  }
+
+  // Don't need parseByte etc. - Byte.parseByte is sufficient.
+
+  public static byte toByte(Object o) {
+    return o instanceof Byte ? (Byte) o
+        : o instanceof Number ? toByte((Number) o)
+        : Byte.parseByte(o.toString());
+  }
+
+  public static byte toByte(Number number) {
+    return number.byteValue();
+  }
+
+  public static char toChar(String s) {
+    return s.charAt(0);
+  }
+
+  public static Character toCharBoxed(String s) {
+    return s.charAt(0);
+  }
+
+  public static short toShort(String s) {
+    return Short.parseShort(s.trim());
+  }
+
+  public static short toShort(Number number) {
+    return number.shortValue();
+  }
+
+  public static short toShort(Object o) {
+    return o instanceof Short ? (Short) o
+        : o instanceof Number ? toShort((Number) o)
+        : o instanceof String ? toShort((String) o)
+        : (Short) cannotConvert(o, short.class);
+  }
+
+  public static int toInt(java.util.Date v) {
+    return toInt(v, LOCAL_TZ);
+  }
+
+  public static int toInt(java.util.Date v, TimeZone timeZone) {
+    return (int) (toLong(v, timeZone)  / DateTimeUtil.MILLIS_PER_DAY);
+  }
+
+  public static Integer toIntOptional(java.util.Date v) {
+    return v == null ? null : toInt(v);
+  }
+
+  public static Integer toIntOptional(java.util.Date v, TimeZone timeZone) {
+    return v == null
+        ? null
+        : toInt(v, timeZone);
+  }
+
+  public static long toLong(Date v) {
+    return toLong(v, LOCAL_TZ);
+  }
+
+  public static int toInt(java.sql.Time v) {
+    return (int) (toLong(v) % DateTimeUtil.MILLIS_PER_DAY);
+  }
+
+  public static Integer toIntOptional(java.sql.Time v) {
+    return v == null ? null : toInt(v);
+  }
+
+  public static int toInt(String s) {
+    return Integer.parseInt(s.trim());
+  }
+
+  public static int toInt(Number number) {
+    return number.intValue();
+  }
+
+  public static int toInt(Object o) {
+    return o instanceof Integer ? (Integer) o
+        : o instanceof Number ? toInt((Number) o)
+        : o instanceof String ? toInt((String) o)
+        : (Integer) cannotConvert(o, int.class);
+  }
+
+  public static long toLong(Timestamp v) {
+    return toLong(v, LOCAL_TZ);
+  }
+
+  // mainly intended for java.sql.Timestamp but works for other dates also
+  public static long toLong(java.util.Date v, TimeZone timeZone) {
+    final long time = v.getTime();
+    return time + timeZone.getOffset(time);
+  }
+
+  // mainly intended for java.sql.Timestamp but works for other dates also
+  public static Long toLongOptional(java.util.Date v) {
+    return v == null ? null : toLong(v, LOCAL_TZ);
+  }
+
+  public static Long toLongOptional(Timestamp v, TimeZone timeZone) {
+    if (v == null) {
+      return null;
+    }
+    return toLong(v, LOCAL_TZ);
+  }
+
+  public static long toLong(String s) {
+    if (s.startsWith("199") && s.contains(":")) {
+      return Timestamp.valueOf(s).getTime();
+    }
+    return Long.parseLong(s.trim());
+  }
+
+  public static long toLong(Number number) {
+    return number.longValue();
+  }
+
+  public static long toLong(Object o) {
+    return o instanceof Long ? (Long) o
+        : o instanceof Number ? toLong((Number) o)
+        : o instanceof String ? toLong((String) o)
+        : (Long) cannotConvert(o, long.class);
+  }
+
+  public static float toFloat(String s) {
+    return Float.parseFloat(s.trim());
+  }
+
+  public static float toFloat(Number number) {
+    return number.floatValue();
+  }
+
+  public static float toFloat(Object o) {
+    return o instanceof Float ? (Float) o
+        : o instanceof Number ? toFloat((Number) o)
+            : o instanceof String ? toFloat((String) o)
+                : (Float) cannotConvert(o, float.class);
+  }
+
+  public static double toDouble(String s) {
+    return Double.parseDouble(s.trim());
+  }
+
+  public static double toDouble(Number number) {
+    return number.doubleValue();
+  }
+
+  public static double toDouble(Object o) {
+    return o instanceof Double ? (Double) o
+        : o instanceof Number ? toDouble((Number) o)
+        : o instanceof String ? toDouble((String) o)
+        : (Double) cannotConvert(o, double.class);
+  }
+
+  public static BigDecimal toBigDecimal(String s) {
+    return new BigDecimal(s.trim());
+  }
+
+  public static BigDecimal toBigDecimal(Number number) {
+    // There are some values of "long" that cannot be represented as "double".
+    // Not so "int". If it isn't a long, go straight to double.
+    return number instanceof BigDecimal ? (BigDecimal) number
+        : number instanceof BigInteger ? new BigDecimal((BigInteger) number)
+        : number instanceof Long ? new BigDecimal(number.longValue())
+        : new BigDecimal(number.doubleValue());
+  }
+
+  public static BigDecimal toBigDecimal(Object o) {
+    return o instanceof Number ? toBigDecimal((Number) o)
+        : toBigDecimal(o.toString());
+  }
+
+  // Don't need shortValueOf etc. - Short.valueOf is sufficient.
+
+  /** Helper for CAST(... AS VARCHAR(maxLength)). */
+  public static String truncate(String s, int maxLength) {
+    return s == null ? null
+        : s.length() > maxLength ? s.substring(0, maxLength)
+        : s;
+  }
+
+  /** Helper for CAST(... AS VARBINARY(maxLength)). */
+  public static ByteString truncate(ByteString s, int maxLength) {
+    return s == null ? null
+        : s.length() > maxLength ? s.substring(0, maxLength)
+        : s;
+  }
+
+  /** SQL {@code POSITION(seek IN string)} function. */
+  public static int position(String seek, String s) {
+    return s.indexOf(seek) + 1;
+  }
+
+  /** SQL {@code POSITION(seek IN string)} function. */
+  public static int position(ByteString seek, ByteString s) {
+    return s.indexOf(seek) + 1;
+  }
+
+  /** Cheap, unsafe, long power. power(2, 3) returns 8. */
+  public static long powerX(long a, long b) {
+    long x = 1;
+    while (b > 0) {
+      x *= a;
+      --b;
+    }
+    return x;
+  }
+
+  /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
+  public static long round(long v, long x) {
+    return truncate(v + x / 2, x);
+  }
+
+  /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
+  public static long truncate(long v, long x) {
+    long remainder = v % x;
+    if (remainder < 0) {
+      remainder += x;
+    }
+    return v - remainder;
+  }
+
+  /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
+  public static int round(int v, int x) {
+    return truncate(v + x / 2, x);
+  }
+
+  /** Helper for rounding. Truncate(12345, 1000) returns 12000. */
+  public static int truncate(int v, int x) {
+    int remainder = v % x;
+    if (remainder < 0) {
+      remainder += x;
+    }
+    return v - remainder;
+  }
+
+  /** Helper for CAST({timestamp} AS VARCHAR(n)). */
+  public static String unixTimestampToString(long timestamp) {
+    final StringBuilder buf = new StringBuilder(17);
+    int date = (int) (timestamp / DateTimeUtil.MILLIS_PER_DAY);
+    int time = (int) (timestamp % DateTimeUtil.MILLIS_PER_DAY);
+    if (time < 0) {
+      --date;
+      time += DateTimeUtil.MILLIS_PER_DAY;
+    }
+    unixDateToString(buf, date);
+    buf.append(' ');
+    unixTimeToString(buf, time);
+    return buf.toString();
+  }
+
+  /** Helper for CAST({timestamp} AS VARCHAR(n)). */
+  public static String unixTimeToString(int time) {
+    final StringBuilder buf = new StringBuilder(8);
+    unixTimeToString(buf, time);
+    return buf.toString();
+  }
+
+  private static void unixTimeToString(StringBuilder buf, int time) {
+    int h = time / 3600000;
+    int time2 = time % 3600000;
+    int m = time2 / 60000;
+    int time3 = time2 % 60000;
+    int s = time3 / 1000;
+    int ms = time3 % 1000;
+    int2(buf, h);
+    buf.append(':');
+    int2(buf, m);
+    buf.append(':');
+    int2(buf, s);
+  }
+
+  /** SQL {@code CURRENT_TIMESTAMP} function. */
+  @NonDeterministic
+  public static long currentTimestamp(DataContext root) {
+    // Cast required for JDK 1.6.
+    return (Long) DataContext.Variable.CURRENT_TIMESTAMP.get(root);
+  }
+
+  /** SQL {@code CURRENT_TIME} function. */
+  @NonDeterministic
+  public static int currentTime(DataContext root) {
+    int time = (int) (currentTimestamp(root) % DateTimeUtil.MILLIS_PER_DAY);
+    if (time < 0) {
+      time += DateTimeUtil.MILLIS_PER_DAY;
+    }
+    return time;
+  }
+
+  /** SQL {@code CURRENT_DATE} function. */
+  @NonDeterministic
+  public static int currentDate(DataContext root) {
+    final long timestamp = currentTimestamp(root);
+    int date = (int) (timestamp / DateTimeUtil.MILLIS_PER_DAY);
+    final int time = (int) (timestamp % DateTimeUtil.MILLIS_PER_DAY);
+    if (time < 0) {
+      --date;
+    }
+    return date;
+  }
+
+  /** SQL {@code LOCAL_TIMESTAMP} function. */
+  @NonDeterministic
+  public static long localTimestamp(DataContext root) {
+    // Cast required for JDK 1.6.
+    return (Long) DataContext.Variable.LOCAL_TIMESTAMP.get(root);
+  }
+
+  /** SQL {@code LOCAL_TIME} function. */
+  @NonDeterministic
+  public static int localTime(DataContext root) {
+    return (int) (localTimestamp(root) % DateTimeUtil.MILLIS_PER_DAY);
+  }
+
+  private static void int2(StringBuilder buf, int i) {
+    buf.append((char) ('0' + (i / 10) % 10));
+    buf.append((char) ('0' + i % 10));
+  }
+
+  private static void int4(StringBuilder buf, int i) {
+    buf.append((char) ('0' + (i / 1000) % 10));
+    buf.append((char) ('0' + (i / 100) % 10));
+    buf.append((char) ('0' + (i / 10) % 10));
+    buf.append((char) ('0' + i % 10));
+  }
+
+  public static int dateStringToUnixDate(String s) {
+    int hyphen1 = s.indexOf('-');
+    int y;
+    int m;
+    int d;
+    if (hyphen1 < 0) {
+      y = Integer.parseInt(s.trim());
+      m = 1;
+      d = 1;
+    } else {
+      y = Integer.parseInt(s.substring(0, hyphen1).trim());
+      final int hyphen2 = s.indexOf('-', hyphen1 + 1);
+      if (hyphen2 < 0) {
+        m = Integer.parseInt(s.substring(hyphen1 + 1).trim());
+        d = 1;
+      } else {
+        m = Integer.parseInt(s.substring(hyphen1 + 1, hyphen2).trim());
+        d = Integer.parseInt(s.substring(hyphen2 + 1).trim());
+      }
+    }
+    return ymdToUnixDate(y, m, d);
+  }
+
+  public static int timeStringToUnixDate(String v) {
+    return timeStringToUnixDate(v, 0);
+  }
+
+  public static int timeStringToUnixDate(String v, int start) {
+    final int colon1 = v.indexOf(':', start);
+    int hour;
+    int minute;
+    int second;
+    int milli;
+    if (colon1 < 0) {
+      hour = Integer.parseInt(v.trim());
+      minute = 1;
+      second = 1;
+      milli = 0;
+    } else {
+      hour = Integer.parseInt(v.substring(start, colon1).trim());
+      final int colon2 = v.indexOf(':', colon1 + 1);
+      if (colon2 < 0) {
+        minute = Integer.parseInt(v.substring(colon1 + 1).trim());
+        second = 1;
+        milli = 0;
+      } else {
+        minute = Integer.parseInt(v.substring(colon1 + 1, colon2).trim());
+        int dot = v.indexOf('.', colon2);
+        if (dot < 0) {
+          second = Integer.parseInt(v.substring(colon2 + 1).trim());
+          milli = 0;
         } else {
-            d = dateStringToUnixDate(s);
-            t = 0;
+          second = Integer.parseInt(v.substring(colon2 + 1, dot).trim());
+          milli = Integer.parseInt(v.substring(dot + 1).trim());
         }
-        return d * DateTimeUtil.MILLIS_PER_DAY + t;
-    }
-
-    /** Helper for CAST({date} AS VARCHAR(n)). */
-    public static String unixDateToString(int date) {
-        final StringBuilder buf = new StringBuilder(10);
-        unixDateToString(buf, date);
-        return buf.toString();
-    }
-
-    private static void unixDateToString(StringBuilder buf, int date) {
-        julianToString(buf, date + EPOCH_JULIAN);
-    }
-
-    private static void julianToString(StringBuilder buf, int julian) {
-        // this shifts the epoch back to astronomical year -4800 instead of the
-        // start of the Christian era in year AD 1 of the proleptic Gregorian
-        // calendar.
-        int j = julian + 32044;
-        int g = j / 146097;
-        int dg = j % 146097;
-        int c = (dg / 36524 + 1) * 3 / 4;
-        int dc = dg - c * 36524;
-        int b = dc / 1461;
-        int db = dc % 1461;
-        int a = (db / 365 + 1) * 3 / 4;
-        int da = db - a * 365;
-
-        // integer number of full years elapsed since March 1, 4801 BC
-        int y = g * 400 + c * 100 + b * 4 + a;
-        // integer number of full months elapsed since the last March 1
-        int m = (da * 5 + 308) / 153 - 2;
-        // number of days elapsed since day 1 of the month
-        int d = da - (m + 4) * 153 / 5 + 122;
-        int year = y - 4800 + (m + 2) / 12;
-        int month = (m + 2) % 12 + 1;
-        int day = d + 1;
-        int4(buf, year);
-        buf.append('-');
-        int2(buf, month);
-        buf.append('-');
-        int2(buf, day);
-    }
-
-    public static long unixDateExtract(TimeUnitRange range, long date) {
-        return julianExtract(range, (int) date + EPOCH_JULIAN);
-    }
-
-    private static int julianExtract(TimeUnitRange range, int julian) {
-        // this shifts the epoch back to astronomical year -4800 instead of the
-        // start of the Christian era in year AD 1 of the proleptic Gregorian
-        // calendar.
-        int j = julian + 32044;
-        int g = j / 146097;
-        int dg = j % 146097;
-        int c = (dg / 36524 + 1) * 3 / 4;
-        int dc = dg - c * 36524;
-        int b = dc / 1461;
-        int db = dc % 1461;
-        int a = (db / 365 + 1) * 3 / 4;
-        int da = db - a * 365;
-
-        // integer number of full years elapsed since March 1, 4801 BC
-        int y = g * 400 + c * 100 + b * 4 + a;
-        // integer number of full months elapsed since the last March 1
-        int m = (da * 5 + 308) / 153 - 2;
-        // number of days elapsed since day 1 of the month
-        int d = da - (m + 4) * 153 / 5 + 122;
-        int year = y - 4800 + (m + 2) / 12;
-        int month = (m + 2) % 12 + 1;
-        int day = d + 1;
-        switch (range) {
-        case YEAR:
-            return year;
-        case MONTH:
-            return month;
-        case DAY:
-            return day;
-        default:
-            throw new AssertionError(range);
-        }
-    }
-
-    public static int ymdToUnixDate(int year, int month, int day) {
-        final int julian = ymdToJulian(year, month, day);
-        return julian - EPOCH_JULIAN;
-    }
-
-    public static int ymdToJulian(int year, int month, int day) {
-        int a = (14 - month) / 12;
-        int y = year + 4800 - a;
-        int m = month + 12 * a - 3;
-        int j = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
-        if (j < 2299161) {
-            j = day + (153 * m + 2) / 5 + 365 * y + y / 4 - 32083;
-        }
-        return j;
-    }
-
-    public static String intervalYearMonthToString(int v, TimeUnitRange range) {
-        final StringBuilder buf = new StringBuilder();
-        if (v >= 0) {
-            buf.append('+');
-        } else {
-            buf.append('-');
-            v = -v;
-        }
-        final int y;
-        final int m;
-        switch (range) {
-        case YEAR:
-            v = roundUp(v, 12);
-            y = v / 12;
-            buf.append(y);
-            break;
-        case YEAR_TO_MONTH:
-            y = v / 12;
-            buf.append(y);
-            buf.append('-');
-            m = v % 12;
-            number(buf, m, 2);
-            break;
-        case MONTH:
-            m = v;
-            buf.append(m);
-            break;
-        default:
-            throw new AssertionError(range);
-        }
-        return buf.toString();
-    }
-
-    private static StringBuilder number(StringBuilder buf, int v, int n) {
-        for (int k = digitCount(v); k < n; k++) {
-            buf.append('0');
-        }
-        return buf.append(v);
-    }
-
-    public static int digitCount(int v) {
-        for (int n = 1;; n++) {
-            v /= 10;
-            if (v == 0) {
-                return n;
-            }
-        }
-    }
-
-    public static String intervalDayTimeToString(long v, TimeUnitRange range, int scale) {
-        final StringBuilder buf = new StringBuilder();
-        if (v >= 0) {
-            buf.append('+');
-        } else {
-            buf.append('-');
-            v = -v;
-        }
-        final long ms;
-        final long s;
-        final long m;
-        final long h;
-        final long d;
-        switch (range) {
-        case DAY_TO_SECOND:
-            v = roundUp(v, powerX(10, 3 - scale));
-            ms = v % 1000;
-            v /= 1000;
-            s = v % 60;
-            v /= 60;
-            m = v % 60;
-            v /= 60;
-            h = v % 24;
-            v /= 24;
-            d = v;
-            buf.append((int) d);
-            buf.append(' ');
-            number(buf, (int) h, 2);
-            buf.append(':');
-            number(buf, (int) m, 2);
-            buf.append(':');
-            number(buf, (int) s, 2);
-            fraction(buf, scale, ms);
-            break;
-        case DAY_TO_MINUTE:
-            v = roundUp(v, 1000 * 60);
-            v /= 1000;
-            v /= 60;
-            m = v % 60;
-            v /= 60;
-            h = v % 24;
-            v /= 24;
-            d = v;
-            buf.append((int) d);
-            buf.append(' ');
-            number(buf, (int) h, 2);
-            buf.append(':');
-            number(buf, (int) m, 2);
-            break;
-        case DAY_TO_HOUR:
-            v = roundUp(v, 1000 * 60 * 60);
-            v /= 1000;
-            v /= 60;
-            v /= 60;
-            h = v % 24;
-            v /= 24;
-            d = v;
-            buf.append((int) d);
-            buf.append(' ');
-            number(buf, (int) h, 2);
-            break;
-        case DAY:
-            v = roundUp(v, 1000 * 60 * 60 * 24);
-            d = v / (1000 * 60 * 60 * 24);
-            buf.append((int) d);
-            break;
-        case HOUR:
-            v = roundUp(v, 1000 * 60 * 60);
-            v /= 1000;
-            v /= 60;
-            v /= 60;
-            h = v;
-            buf.append((int) h);
-            break;
-        case HOUR_TO_MINUTE:
-            v = roundUp(v, 1000 * 60);
-            v /= 1000;
-            v /= 60;
-            m = v % 60;
-            v /= 60;
-            h = v;
-            buf.append((int) h);
-            buf.append(':');
-            number(buf, (int) m, 2);
-            break;
-        case HOUR_TO_SECOND:
-            v = roundUp(v, powerX(10, 3 - scale));
-            ms = v % 1000;
-            v /= 1000;
-            s = v % 60;
-            v /= 60;
-            m = v % 60;
-            v /= 60;
-            h = v;
-            buf.append((int) h);
-            buf.append(':');
-            number(buf, (int) m, 2);
-            buf.append(':');
-            number(buf, (int) s, 2);
-            fraction(buf, scale, ms);
-            break;
-        case MINUTE_TO_SECOND:
-            v = roundUp(v, powerX(10, 3 - scale));
-            ms = v % 1000;
-            v /= 1000;
-            s = v % 60;
-            v /= 60;
-            m = v;
-            buf.append((int) m);
-            buf.append(':');
-            number(buf, (int) s, 2);
-            fraction(buf, scale, ms);
-            break;
-        case MINUTE:
-            v = roundUp(v, 1000 * 60);
-            v /= 1000;
-            v /= 60;
-            m = v;
-            buf.append((int) m);
-            break;
-        case SECOND:
-            v = roundUp(v, powerX(10, 3 - scale));
-            ms = v % 1000;
-            v /= 1000;
-            s = v;
-            buf.append((int) s);
-            fraction(buf, scale, ms);
-            break;
-        default:
-            throw new AssertionError(range);
-        }
-        return buf.toString();
-    }
-
-    /**
-     * Rounds a dividend to the nearest divisor.
-     * For example roundUp(31, 10) yields 30; roundUp(37, 10) yields 40.
-     * @param dividend Number to be divided
-     * @param divisor Number to divide by
-     * @return Rounded dividend
-     */
-    private static long roundUp(long dividend, long divisor) {
-        long remainder = dividend % divisor;
-        dividend -= remainder;
-        if (remainder * 2 > divisor) {
-            dividend += divisor;
-        }
-        return dividend;
-    }
-
-    private static int roundUp(int dividend, int divisor) {
-        int remainder = dividend % divisor;
-        dividend -= remainder;
-        if (remainder * 2 > divisor) {
-            dividend += divisor;
-        }
-        return dividend;
-    }
-
-    private static void fraction(StringBuilder buf, int scale, long ms) {
-        if (scale > 0) {
-            buf.append('.');
-            long v1 = scale == 3 ? ms : scale == 2 ? ms / 10 : scale == 1 ? ms / 100 : 0;
-            number(buf, (int) v1, scale);
-        }
-    }
-
-    /** Helper for "array element reference". Caller has already ensured that
-     * array and index are not null. Index is 1-based, per SQL. */
-    public static Object arrayItem(List list, int item) {
-        if (item < 1 || item > list.size()) {
-            return null;
-        }
-        return list.get(item - 1);
-    }
-
-    /** Helper for "map element reference". Caller has already ensured that
-     * array and index are not null. Index is 1-based, per SQL. */
-    public static Object mapItem(Map map, Object item) {
-        return map.get(item);
-    }
-
-    /** Implements the {@code [ ... ]} operator on an object whose type is not
-     * known until runtime.
-     */
-    public static Object item(Object object, Object index) {
-        if (object instanceof Map) {
-            return ((Map) object).get(index);
-        }
-        if (object instanceof List && index instanceof Number) {
-            List list = (List) object;
-            return list.get(((Number) index).intValue());
-        }
-        return null;
-    }
-
-    /** NULL &rarr; FALSE, FALSE &rarr; FALSE, TRUE &rarr; TRUE. */
-    public static boolean isTrue(Boolean b) {
-        return b != null && b;
-    }
-
-    /** NULL &rarr; TRUE, FALSE &rarr; FALSE, TRUE &rarr; TRUE. */
-    public static boolean isNotFalse(Boolean b) {
-        return b == null || b;
-    }
-
-    /** NULL &rarr; NULL, FALSE &rarr; TRUE, TRUE &rarr; FALSE. */
-    public static Boolean not(Boolean b) {
-        return (b == null) ? null : !b;
-    }
-
-    /** Converts a JDBC array to a list. */
-    public static List arrayToList(final java.sql.Array a) {
-        if (a == null) {
-            return null;
-        }
-        try {
-            return Primitive.asList(a.getArray());
-        } catch (SQLException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /** Support the SLICE function. */
-    public static List slice(List list) {
-        return list;
-    }
-
-    /** Support the ELEMENT function. */
-    public static Object element(List list) {
-        switch (list.size()) {
-        case 0:
-            return null;
-        case 1:
-            return list.get(0);
-        default:
-            throw new RuntimeException("more than one value");
-        }
-    }
-
-    /** Returns a lambda that converts a list to an enumerable. */
-    public static <E> Function1<List<E>, Enumerable<E>> listToEnumerable() {
-        //noinspection unchecked
-        return (Function1<List<E>, Enumerable<E>>) (Function1) LIST_AS_ENUMERABLE;
-    }
-
-    /** A range of time units. The first is more significant than the
-     * other (e.g. year-to-day) or the same as the other
-     * (e.g. month). */
-    public enum TimeUnitRange {
-        YEAR, YEAR_TO_MONTH, MONTH, DAY, DAY_TO_HOUR, DAY_TO_MINUTE, DAY_TO_SECOND, HOUR, HOUR_TO_MINUTE, HOUR_TO_SECOND, MINUTE, MINUTE_TO_SECOND, SECOND;
-
-        /** Whether this is in the YEAR-TO-MONTH family of intervals. */
-        public boolean monthly() {
-            return ordinal() <= MONTH.ordinal();
-        }
-    }
+      }
+    }
+    return hour * (int) DateTimeUtil.MILLIS_PER_HOUR
+        + minute * (int) DateTimeUtil.MILLIS_PER_MINUTE
+        + second * (int) DateTimeUtil.MILLIS_PER_SECOND
+        + milli;
+  }
+
+  public static long timestampStringToUnixDate(String s) {
+    final long d;
+    final long t;
+    s = s.trim();
+    int space = s.indexOf(' ');
+    if (space >= 0) {
+      d = dateStringToUnixDate(s.substring(0, space));
+      t = timeStringToUnixDate(s, space + 1);
+    } else {
+      d = dateStringToUnixDate(s);
+      t = 0;
+    }
+    return d * DateTimeUtil.MILLIS_PER_DAY + t;
+  }
+
+  /** Helper for CAST({date} AS VARCHAR(n)). */
+  public static String unixDateToString(int date) {
+    final StringBuilder buf = new StringBuilder(10);
+    unixDateToString(buf, date);
+    return buf.toString();
+  }
+
+  private static void unixDateToString(StringBuilder buf, int date) {
+    julianToString(buf, date + EPOCH_JULIAN);
+  }
+
+  private static void julianToString(StringBuilder buf, int julian) {
+    // this shifts the epoch back to astronomical year -4800 instead of the
+    // start of the Christian era in year AD 1 of the proleptic Gregorian
+    // calendar.
+    int j = julian + 32044;
+    int g = j / 146097;
+    int dg = j % 146097;
+    int c = (dg / 36524 + 1) * 3 / 4;
+    int dc = dg - c * 36524;
+    int b = dc / 1461;
+    int db = dc % 1461;
+    int a = (db / 365 + 1) * 3 / 4;
+    int da = db - a * 365;
+
+    // integer number of full years elapsed since March 1, 4801 BC
+    int y = g * 400 + c * 100 + b * 4 + a;
+    // integer number of full months elapsed since the last March 1
+    int m = (da * 5 + 308) / 153 - 2;
+    // number of days elapsed since day 1 of the month
+    int d = da - (m + 4) * 153 / 5 + 122;
+    int year = y - 4800 + (m + 2) / 12;
+    int month = (m + 2) % 12 + 1;
+    int day = d + 1;
+    int4(buf, year);
+    buf.append('-');
+    int2(buf, month);
+    buf.append('-');
+    int2(buf, day);
+  }
+
+  public static long unixDateExtract(TimeUnitRange range, long date) {
+    return julianExtract(range, (int) date + EPOCH_JULIAN);
+  }
+
+  private static int julianExtract(TimeUnitRange range, int julian) {
+    // this shifts the epoch back to astronomical year -4800 instead of the
+    // start of the Christian era in year AD 1 of the proleptic Gregorian
+    // calendar.
+    int j = julian + 32044;
+    int g = j / 146097;
+    int dg = j % 146097;
+    int c = (dg / 36524 + 1) * 3 / 4;
+    int dc = dg - c * 36524;
+    int b = dc / 1461;
+    int db = dc % 1461;
+    int a = (db / 365 + 1) * 3 / 4;
+    int da = db - a * 365;
+
+    // integer number of full years elapsed since March 1, 4801 BC

<TRUNCATED>


[09/14] incubator-kylin git commit: update routes.json , rm jsoneditor config

Posted by li...@apache.org.
update routes.json ,rm jsoneditor config


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

Branch: refs/heads/0.7
Commit: d38cbd1a21bb86d0252bacf00c6b7ae723c5ad2a
Parents: f3cc299
Author: jiazhong <ji...@ebay.com>
Authored: Tue Jun 9 18:20:00 2015 +0800
Committer: jiazhong <ji...@ebay.com>
Committed: Tue Jun 9 18:20:00 2015 +0800

----------------------------------------------------------------------
 webapp/app/routes.json | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/d38cbd1a/webapp/app/routes.json
----------------------------------------------------------------------
diff --git a/webapp/app/routes.json b/webapp/app/routes.json
index e13656e..9f13c70 100644
--- a/webapp/app/routes.json
+++ b/webapp/app/routes.json
@@ -32,14 +32,6 @@
         }
     },
     {
-        "url": "/cubes/add/json",
-        "params": {
-            "templateUrl": "partials/cubes/cube_json_edit.html",
-            "tab": "cubes",
-            "controller": "CubeEditCtrl"
-        }
-    },
-    {
         "url": "/cubes/edit/:cubeName/json",
         "params": {
             "templateUrl": "partials/cubes/cube_json_edit.html",


[11/14] incubator-kylin git commit: use fk on fact table replace pk on lookup table when generate rowkey&aggregation group, distinct rowkey ang aggregation group

Posted by li...@apache.org.
use fk on fact table replace pk on lookup table when generate rowkey&aggregation group,distinct rowkey ang aggregation group


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

Branch: refs/heads/0.7
Commit: f37360de7746628cac557014fec3eb5dc4dde8aa
Parents: 00d81f9
Author: jiazhong <ji...@ebay.com>
Authored: Wed Jun 10 20:31:53 2015 +0800
Committer: jiazhong <ji...@ebay.com>
Committed: Wed Jun 10 20:32:51 2015 +0800

----------------------------------------------------------------------
 webapp/app/js/controllers/cubeEdit.js          | 41 ++++++++++++++++++---
 webapp/app/partials/cubeDesigner/overview.html |  2 +-
 2 files changed, 36 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f37360de/webapp/app/js/controllers/cubeEdit.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/cubeEdit.js b/webapp/app/js/controllers/cubeEdit.js
index e371e3f..7f8cb27 100755
--- a/webapp/app/js/controllers/cubeEdit.js
+++ b/webapp/app/js/controllers/cubeEdit.js
@@ -233,7 +233,7 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
           }, function (request) {
             if (request.successful) {
               $scope.state.cubeSchema = request.cubeDescData;
-              
+
               SweetAlert.swal('', 'Created the cube successfully.', 'success');
 
               $location.path("/cubes");
@@ -299,9 +299,18 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
 
   function reGenerateRowKey() {
     $log.log("reGen rowkey & agg group");
+    var fk_pk = {};
     var tmpRowKeyColumns = [];
     var tmpAggregationItems = [];//put all aggregation item
     var hierarchyItemArray = [];//put all hierarchy items
+
+    // build fk_pk map
+    angular.forEach($scope.metaModel.model.lookups, function (_lookup, index) {
+      for(var i = 0;i< _lookup.join.foreign_key.length;i++){
+        fk_pk[_lookup.join.primary_key[i]] = _lookup.join.foreign_key[i];
+      }
+    });
+
     angular.forEach($scope.cubeMetaFrame.dimensions, function (dimension, index) {
 
       //derived column
@@ -325,11 +334,12 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
 
             tmpAggregationItems.push(fk);
           }
-        })
+        });
 
       }
+
       //normal column
-      else if (dimension.column && !dimension.hierarchy && dimension.column.length == 1) {
+      if (dimension.column && !dimension.hierarchy && dimension.column.length == 1) {
         for (var i = 0; i < tmpRowKeyColumns.length; i++) {
           if (tmpRowKeyColumns[i].column == dimension.column[0])
             break;
@@ -345,13 +355,21 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
         }
       }
       // hierarchy
-      if (dimension.hierarchy && dimension.column.length) {
+     else if (dimension.hierarchy && dimension.column.length) {
         var hierarchyUnit = [];
+
         angular.forEach(dimension.column, function (hier_column, index) {
+
+          //use fk instead of fk as rowkey and aggregation item in hierarchy
+          if(hier_column in fk_pk){
+            hier_column = fk_pk[hier_column];
+          }
+
           for (var i = 0; i < tmpRowKeyColumns.length; i++) {
             if (tmpRowKeyColumns[i].column == hier_column)
               break;
           }
+
           if (i == tmpRowKeyColumns.length) {
             tmpRowKeyColumns.push({
               "column": hier_column,
@@ -361,6 +379,7 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
             });
             tmpAggregationItems.push(hier_column);
           }
+
           if (hierarchyUnit.indexOf(hier_column) == -1) {
             hierarchyUnit.push(hier_column);
           }
@@ -370,10 +389,11 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
         }
       }
 
-    });
 
 
-    //rm mandatory column from aggregation item
+    });
+
+      //rm mandatory column from aggregation item
     angular.forEach($scope.cubeMetaFrame.rowkey.rowkey_columns, function (value, index) {
       if (value.mandatory) {
         tmpAggregationItems = _.filter(tmpAggregationItems, function (item) {
@@ -434,7 +454,16 @@ KylinApp.controller('CubeEditCtrl', function ($scope, $q, $routeParams, $locatio
         }
       });
 
+      //distinct hierarchyItem
       var hierarchyItems = hierarchyItemArray.join().split(",");
+      var _hierarchyItems = [];
+      angular.forEach(hierarchyItems, function (item, index) {
+        if (_hierarchyItems.indexOf(item) == -1) {
+          _hierarchyItems.push(item);
+        }
+      });
+      hierarchyItems = _hierarchyItems;
+
       var unHierarchyItems = increasedData(hierarchyItems, newUniqAggregationItem);
       //hierarchyItems
       var increasedDataGroups = sliceGroupItemToGroups(unHierarchyItems);

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/f37360de/webapp/app/partials/cubeDesigner/overview.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/cubeDesigner/overview.html b/webapp/app/partials/cubeDesigner/overview.html
index bbb5dc6..c1f6e71 100644
--- a/webapp/app/partials/cubeDesigner/overview.html
+++ b/webapp/app/partials/cubeDesigner/overview.html
@@ -34,7 +34,7 @@
                     <!--Fact Table-->
                     <tr>
                         <th>Fact Table</th>
-                        <td class="tb-breakword">{{cubeMetaFrame.fact_table}}</td>
+                        <td class="tb-breakword">{{metaModel.model.fact_table}}</td>
                     </tr>
                     <!--Lookup Table-->
                     <tr>


[03/14] incubator-kylin git commit: Fix necessary ColumnMetaData order for Calcite (Optic)

Posted by li...@apache.org.
Fix necessary ColumnMetaData order for Calcite (Optic)

Signed-off-by: Li, Yang <ya...@ebay.com>


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

Branch: refs/heads/0.7
Commit: 716bd9dcc2ab43e642b106db838458a684932495
Parents: 724ccf9
Author: Sébastien Jelsch <mu...@gmail.com>
Authored: Mon Jun 8 12:05:20 2015 +0200
Committer: Li, Yang <ya...@ebay.com>
Committed: Tue Jun 9 10:41:45 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/jdbc/util/SQLTypeMap.java  | 366 +++++++++----------
 1 file changed, 183 insertions(+), 183 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/716bd9dc/jdbc/src/main/java/org/apache/kylin/jdbc/util/SQLTypeMap.java
----------------------------------------------------------------------
diff --git a/jdbc/src/main/java/org/apache/kylin/jdbc/util/SQLTypeMap.java b/jdbc/src/main/java/org/apache/kylin/jdbc/util/SQLTypeMap.java
index ec7df0b..c4090ab 100644
--- a/jdbc/src/main/java/org/apache/kylin/jdbc/util/SQLTypeMap.java
+++ b/jdbc/src/main/java/org/apache/kylin/jdbc/util/SQLTypeMap.java
@@ -1,183 +1,183 @@
-/*
- * 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.kylin.jdbc.util;
-
-import java.math.BigDecimal;
-import java.sql.Date;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.HashMap;
-import java.util.Map;
-
-import net.hydromatic.avatica.ColumnMetaData;
-import net.hydromatic.avatica.ColumnMetaData.Rep;
-
-import org.apache.kylin.jdbc.stub.KylinColumnMetaData;
-
-/**
- * Util class to handle type gap between sql types and java types.
- * 
- * @author xduo
- * 
- */
-public class SQLTypeMap {
-
-    public final static Map<String, ColumnMetaData> schemaMetaTypeMapping = new HashMap<String, ColumnMetaData>();
-
-    public final static Map<String, ColumnMetaData> columnMetaTypeMapping = new HashMap<String, ColumnMetaData>();
-
-    public final static Map<String, ColumnMetaData> tableMetaTypeMapping = new HashMap<String, ColumnMetaData>();
-
-    static {
-        schemaMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        schemaMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_CATALOG", "TABLE_CATALOG", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-
-        tableMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_CAT", "TABLE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TABLE_NAME", KylinColumnMetaData.dummy(2, "TABLE_NAME", "TABLE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TABLE_TYPE", KylinColumnMetaData.dummy(3, "TABLE_TYPE", "TABLE_TYPE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("REMARKS", KylinColumnMetaData.dummy(4, "REMARKS", "REMARKS", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TYPE_CAT", KylinColumnMetaData.dummy(5, "TYPE_CAT", "TYPE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TYPE_SCHEM", KylinColumnMetaData.dummy(6, "TYPE_SCHEM", "TYPE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("TYPE_NAME", KylinColumnMetaData.dummy(7, "TYPE_NAME", "TYPE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("SELF_REFERENCING_COL_NAME", KylinColumnMetaData.dummy(8, "SELF_REFERENCING_COL_NAME", "SELF_REFERENCING_COL_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        tableMetaTypeMapping.put("REF_GENERATION", KylinColumnMetaData.dummy(9, "REF_GENERATION", "REF_GENERATION", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-
-        columnMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_CAT", "TABLE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("TABLE_NAME", KylinColumnMetaData.dummy(2, "TABLE_NAME", "TABLE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("COLUMN_NAME", KylinColumnMetaData.dummy(3, "COLUMN_NAME", "COLUMN_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("DATA_TYPE", KylinColumnMetaData.dummy(4, "DATA_TYPE", "DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("TYPE_NAME", KylinColumnMetaData.dummy(5, "TYPE_NAME", "TYPE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("COLUMN_SIZE", KylinColumnMetaData.dummy(6, "COLUMN_SIZE", "COLUMN_SIZE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("BUFFER_LENGTH", KylinColumnMetaData.dummy(7, "BUFFER_LENGTH", "BUFFER_LENGTH", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("DECIMAL_DIGITS", KylinColumnMetaData.dummy(8, "DECIMAL_DIGITS", "DECIMAL_DIGITS", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("NUM_PREC_RADIX", KylinColumnMetaData.dummy(9, "NUM_PREC_RADIX", "NUM_PREC_RADIX", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("NULLABLE", KylinColumnMetaData.dummy(10, "NULLABLE", "NULLABLE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("REMARKS", KylinColumnMetaData.dummy(11, "REMARKS", "REMARKS", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("COLUMN_DEF", KylinColumnMetaData.dummy(12, "COLUMN_DEF", "COLUMN_DEF", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("SQL_DATA_TYPE", KylinColumnMetaData.dummy(13, "SQL_DATA_TYPE", "SQL_DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("SQL_DATETIME_SUB", KylinColumnMetaData.dummy(14, "SQL_DATETIME_SUB", "SQL_DATETIME_SUB", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("CHAR_OCTET_LENGTH", KylinColumnMetaData.dummy(15, "CHAR_OCTET_LENGTH", "CHAR_OCTET_LENGTH", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("ORDINAL_POSITION", KylinColumnMetaData.dummy(16, "ORDINAL_POSITION", "ORDINAL_POSITION", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("IS_NULLABLE", KylinColumnMetaData.dummy(17, "IS_NULLABLE", "IS_NULLABLE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("SCOPE_CATALOG", KylinColumnMetaData.dummy(18, "SCOPE_CATALOG", "SCOPE_CATALOG", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("SCOPE_TABLE", KylinColumnMetaData.dummy(19, "SCOPE_TABLE", "SCOPE_TABLE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("SOURCE_DATA_TYPE", KylinColumnMetaData.dummy(20, "SOURCE_DATA_TYPE", "SOURCE_DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
-        columnMetaTypeMapping.put("IS_AUTOINCREMENT", KylinColumnMetaData.dummy(21, "IS_AUTOINCREMENT", "IS_AUTOINCREMENT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-        columnMetaTypeMapping.put("IS_GENERATEDCOLUMN", KylinColumnMetaData.dummy(22, "IS_GENERATEDCOLUMN", "IS_GENERATEDCOLUMN", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
-    }
-
-    @SuppressWarnings("rawtypes")
-    public static Class convert(int sqlType) {
-        Class result = Object.class;
-
-        switch (sqlType) {
-        case Types.CHAR:
-        case Types.VARCHAR:
-        case Types.LONGVARCHAR:
-            result = String.class;
-            break;
-        case Types.NUMERIC:
-        case Types.DECIMAL:
-            result = BigDecimal.class;
-            break;
-        case Types.BIT:
-            result = Boolean.class;
-            break;
-        case Types.TINYINT:
-            result = Byte.class;
-            break;
-        case Types.SMALLINT:
-            result = Short.class;
-            break;
-        case Types.INTEGER:
-            result = Integer.class;
-            break;
-        case Types.BIGINT:
-            result = Long.class;
-            break;
-        case Types.REAL:
-        case Types.FLOAT:
-        case Types.DOUBLE:
-            result = Double.class;
-            break;
-        case Types.BINARY:
-        case Types.VARBINARY:
-        case Types.LONGVARBINARY:
-            result = Byte[].class;
-            break;
-        case Types.DATE:
-            result = Date.class;
-            break;
-        case Types.TIME:
-            result = Time.class;
-            break;
-        case Types.TIMESTAMP:
-            result = Timestamp.class;
-            break;
-        }
-
-        return result;
-    }
-
-    public static Object wrapObject(String value, int sqlType) {
-        if (null == value) {
-            return null;
-        }
-
-        switch (sqlType) {
-        case Types.CHAR:
-        case Types.VARCHAR:
-        case Types.LONGVARCHAR:
-            return value;
-        case Types.NUMERIC:
-        case Types.DECIMAL:
-            return new BigDecimal(value);
-        case Types.BIT:
-            return Boolean.parseBoolean(value);
-        case Types.TINYINT:
-            return Byte.valueOf(value);
-        case Types.SMALLINT:
-            return Short.valueOf(value);
-        case Types.INTEGER:
-            return Integer.parseInt(value);
-        case Types.BIGINT:
-            return Long.parseLong(value);
-        case Types.FLOAT:
-            return Float.parseFloat(value);
-        case Types.REAL:
-        case Types.DOUBLE:
-            return Double.parseDouble(value);
-        case Types.BINARY:
-        case Types.VARBINARY:
-        case Types.LONGVARBINARY:
-            return value.getBytes();
-        case Types.DATE:
-            return Date.valueOf(value);
-        case Types.TIME:
-            return Time.valueOf(value);
-        case Types.TIMESTAMP:
-            return Timestamp.valueOf(value);
-        }
-
-        return value;
-    }
-}
+/*
+ * 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.kylin.jdbc.util;
+
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.sql.Types;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import net.hydromatic.avatica.ColumnMetaData;
+import net.hydromatic.avatica.ColumnMetaData.Rep;
+
+import org.apache.kylin.jdbc.stub.KylinColumnMetaData;
+
+/**
+ * Util class to handle type gap between sql types and java types.
+ * 
+ * @author xduo
+ * 
+ */
+public class SQLTypeMap {
+
+    public final static Map<String, ColumnMetaData> schemaMetaTypeMapping = new LinkedHashMap<String, ColumnMetaData>();
+
+    public final static Map<String, ColumnMetaData> columnMetaTypeMapping = new LinkedHashMap<String, ColumnMetaData>();
+
+    public final static Map<String, ColumnMetaData> tableMetaTypeMapping = new LinkedHashMap<String, ColumnMetaData>();
+
+    static {
+        schemaMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        schemaMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_CATALOG", "TABLE_CATALOG", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+
+        tableMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_CAT", "TABLE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TABLE_NAME", KylinColumnMetaData.dummy(2, "TABLE_NAME", "TABLE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TABLE_TYPE", KylinColumnMetaData.dummy(3, "TABLE_TYPE", "TABLE_TYPE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("REMARKS", KylinColumnMetaData.dummy(4, "REMARKS", "REMARKS", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TYPE_CAT", KylinColumnMetaData.dummy(5, "TYPE_CAT", "TYPE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TYPE_SCHEM", KylinColumnMetaData.dummy(6, "TYPE_SCHEM", "TYPE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("TYPE_NAME", KylinColumnMetaData.dummy(7, "TYPE_NAME", "TYPE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("SELF_REFERENCING_COL_NAME", KylinColumnMetaData.dummy(8, "SELF_REFERENCING_COL_NAME", "SELF_REFERENCING_COL_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        tableMetaTypeMapping.put("REF_GENERATION", KylinColumnMetaData.dummy(9, "REF_GENERATION", "REF_GENERATION", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+
+        columnMetaTypeMapping.put("TABLE_CAT", KylinColumnMetaData.dummy(0, "TABLE_CAT", "TABLE_CAT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("TABLE_SCHEM", KylinColumnMetaData.dummy(1, "TABLE_SCHEM", "TABLE_SCHEM", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("TABLE_NAME", KylinColumnMetaData.dummy(2, "TABLE_NAME", "TABLE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("COLUMN_NAME", KylinColumnMetaData.dummy(3, "COLUMN_NAME", "COLUMN_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("DATA_TYPE", KylinColumnMetaData.dummy(4, "DATA_TYPE", "DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("TYPE_NAME", KylinColumnMetaData.dummy(5, "TYPE_NAME", "TYPE_NAME", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("COLUMN_SIZE", KylinColumnMetaData.dummy(6, "COLUMN_SIZE", "COLUMN_SIZE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("BUFFER_LENGTH", KylinColumnMetaData.dummy(7, "BUFFER_LENGTH", "BUFFER_LENGTH", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("DECIMAL_DIGITS", KylinColumnMetaData.dummy(8, "DECIMAL_DIGITS", "DECIMAL_DIGITS", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("NUM_PREC_RADIX", KylinColumnMetaData.dummy(9, "NUM_PREC_RADIX", "NUM_PREC_RADIX", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("NULLABLE", KylinColumnMetaData.dummy(10, "NULLABLE", "NULLABLE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("REMARKS", KylinColumnMetaData.dummy(11, "REMARKS", "REMARKS", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("COLUMN_DEF", KylinColumnMetaData.dummy(12, "COLUMN_DEF", "COLUMN_DEF", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("SQL_DATA_TYPE", KylinColumnMetaData.dummy(13, "SQL_DATA_TYPE", "SQL_DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("SQL_DATETIME_SUB", KylinColumnMetaData.dummy(14, "SQL_DATETIME_SUB", "SQL_DATETIME_SUB", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("CHAR_OCTET_LENGTH", KylinColumnMetaData.dummy(15, "CHAR_OCTET_LENGTH", "CHAR_OCTET_LENGTH", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("ORDINAL_POSITION", KylinColumnMetaData.dummy(16, "ORDINAL_POSITION", "ORDINAL_POSITION", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("IS_NULLABLE", KylinColumnMetaData.dummy(17, "IS_NULLABLE", "IS_NULLABLE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("SCOPE_CATALOG", KylinColumnMetaData.dummy(18, "SCOPE_CATALOG", "SCOPE_CATALOG", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("SCOPE_TABLE", KylinColumnMetaData.dummy(19, "SCOPE_TABLE", "SCOPE_TABLE", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("SOURCE_DATA_TYPE", KylinColumnMetaData.dummy(20, "SOURCE_DATA_TYPE", "SOURCE_DATA_TYPE", ColumnMetaData.scalar(Types.INTEGER, "integer", Rep.INTEGER), true));
+        columnMetaTypeMapping.put("IS_AUTOINCREMENT", KylinColumnMetaData.dummy(21, "IS_AUTOINCREMENT", "IS_AUTOINCREMENT", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+        columnMetaTypeMapping.put("IS_GENERATEDCOLUMN", KylinColumnMetaData.dummy(22, "IS_GENERATEDCOLUMN", "IS_GENERATEDCOLUMN", ColumnMetaData.scalar(Types.VARCHAR, "varchar", Rep.STRING), true));
+    }
+
+    @SuppressWarnings("rawtypes")
+    public static Class convert(int sqlType) {
+        Class result = Object.class;
+
+        switch (sqlType) {
+        case Types.CHAR:
+        case Types.VARCHAR:
+        case Types.LONGVARCHAR:
+            result = String.class;
+            break;
+        case Types.NUMERIC:
+        case Types.DECIMAL:
+            result = BigDecimal.class;
+            break;
+        case Types.BIT:
+            result = Boolean.class;
+            break;
+        case Types.TINYINT:
+            result = Byte.class;
+            break;
+        case Types.SMALLINT:
+            result = Short.class;
+            break;
+        case Types.INTEGER:
+            result = Integer.class;
+            break;
+        case Types.BIGINT:
+            result = Long.class;
+            break;
+        case Types.REAL:
+        case Types.FLOAT:
+        case Types.DOUBLE:
+            result = Double.class;
+            break;
+        case Types.BINARY:
+        case Types.VARBINARY:
+        case Types.LONGVARBINARY:
+            result = Byte[].class;
+            break;
+        case Types.DATE:
+            result = Date.class;
+            break;
+        case Types.TIME:
+            result = Time.class;
+            break;
+        case Types.TIMESTAMP:
+            result = Timestamp.class;
+            break;
+        }
+
+        return result;
+    }
+
+    public static Object wrapObject(String value, int sqlType) {
+        if (null == value) {
+            return null;
+        }
+
+        switch (sqlType) {
+        case Types.CHAR:
+        case Types.VARCHAR:
+        case Types.LONGVARCHAR:
+            return value;
+        case Types.NUMERIC:
+        case Types.DECIMAL:
+            return new BigDecimal(value);
+        case Types.BIT:
+            return Boolean.parseBoolean(value);
+        case Types.TINYINT:
+            return Byte.valueOf(value);
+        case Types.SMALLINT:
+            return Short.valueOf(value);
+        case Types.INTEGER:
+            return Integer.parseInt(value);
+        case Types.BIGINT:
+            return Long.parseLong(value);
+        case Types.FLOAT:
+            return Float.parseFloat(value);
+        case Types.REAL:
+        case Types.DOUBLE:
+            return Double.parseDouble(value);
+        case Types.BINARY:
+        case Types.VARBINARY:
+        case Types.LONGVARBINARY:
+            return value.getBytes();
+        case Types.DATE:
+            return Date.valueOf(value);
+        case Types.TIME:
+            return Time.valueOf(value);
+        case Types.TIMESTAMP:
+            return Timestamp.valueOf(value);
+        }
+
+        return value;
+    }
+}


[04/14] incubator-kylin git commit: KYLIN-813 , show segment start/end Time in Hbase tab , update font-awesome version

Posted by li...@apache.org.
KYLIN-813 ,show segment start/end Time in Hbase tab ,update font-awesome version


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

Branch: refs/heads/0.7
Commit: b3b0f2f957fbb58cf0f61ecc72afd658ceebfcdb
Parents: 716bd9d
Author: jiazhong <ji...@ebay.com>
Authored: Tue Jun 9 13:08:10 2015 +0800
Committer: jiazhong <ji...@ebay.com>
Committed: Tue Jun 9 13:09:08 2015 +0800

----------------------------------------------------------------------
 .../kylin/rest/controller/CubeController.java   |  2 +
 .../kylin/rest/response/HBaseResponse.java      | 26 ++++++++
 webapp/app/index.html                           |  1 -
 webapp/app/js/controllers/index.js              | 44 -------------
 webapp/app/partials/header.html                 |  2 +-
 webapp/app/partials/home.html                   | 65 --------------------
 webapp/app/routes.json                          |  9 +--
 webapp/bower.json                               |  2 +-
 8 files changed, 31 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java b/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
index 51224b8..26c9811 100644
--- a/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
+++ b/server/src/main/java/org/apache/kylin/rest/controller/CubeController.java
@@ -449,6 +449,8 @@ public class CubeController extends BasicController {
             }
 
             hr.setTableName(tableName);
+            hr.setDateRangeStart(segment.getDateRangeStart());
+            hr.setDateRangeEnd(segment.getDateRangeEnd());
             hbase.add(hr);
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/server/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java b/server/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java
index cd32ae5..302cb02 100644
--- a/server/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java
+++ b/server/src/main/java/org/apache/kylin/rest/response/HBaseResponse.java
@@ -25,6 +25,8 @@ public class HBaseResponse implements Serializable {
     private String tableName;
     private long tableSize;
     private int regionCount;
+    private long dateRangeStart;
+    private long dateRangeEnd;
 
     public HBaseResponse() {
     }
@@ -73,4 +75,28 @@ public class HBaseResponse implements Serializable {
     public void setRegionCount(int regionCount) {
         this.regionCount = regionCount;
     }
+
+    /**
+     * @return the segmentStartTime
+     */
+    public long getDateRangeStart() {
+        return dateRangeStart;
+    }
+
+    /**
+     * @param segmentStartTime
+     *            the segmentStartTime to set
+     */
+    public void setDateRangeStart(long dateRangeStart) { this.dateRangeStart = dateRangeStart; }
+
+    /**
+     * @return the segmentEndTime
+     */
+    public long getDateRangeEnd() { return dateRangeEnd; }
+
+    /**
+     * @param segmentEndTime
+     *            the segmentEndTime to set
+     */
+    public void setDateRangeEnd(long dateRangeEnd) { this.dateRangeEnd = dateRangeEnd; }
 }

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/app/index.html
----------------------------------------------------------------------
diff --git a/webapp/app/index.html b/webapp/app/index.html
index 44021a9..6824498 100644
--- a/webapp/app/index.html
+++ b/webapp/app/index.html
@@ -140,7 +140,6 @@
 <script src="js/model/jobListModel.js"></script>
 
 <script src="js/controllers/page.js"></script>
-<script src="js/controllers/index.js"></script>
 <script src="js/controllers/access.js"></script>
 <script src="js/controllers/auth.js"></script>
 <script src="js/controllers/cubes.js"></script>

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/app/js/controllers/index.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/index.js b/webapp/app/js/controllers/index.js
deleted file mode 100644
index a648c1d..0000000
--- a/webapp/app/js/controllers/index.js
+++ /dev/null
@@ -1,44 +0,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.
- */
-
-'use strict';
-
-KylinApp.controller('IndexCtrl', function ($scope, $location, $anchorScroll) {
-  // Settings about carousel presentation.
-  $scope.myInterval = 5000;
-  // Data url for 1x1 pixel transparent gif.
-  var carouselImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
-
-  $scope.slides = [
-    {
-      image: carouselImg,
-      caption: 'Kylin',
-      text: 'Get your data ready for analytics'
-    },
-    {
-      image: carouselImg,
-      caption: 'Kylin',
-      text: 'Process and transform data from multiple sources'
-    },
-    {
-      image: carouselImg,
-      caption: 'Kylin',
-      text: 'Harness the power of Hadoop with zero coding and no deployment'
-    }
-  ];
-});

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/app/partials/header.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/header.html b/webapp/app/partials/header.html
index 937f56c..eb94664 100644
--- a/webapp/app/partials/header.html
+++ b/webapp/app/partials/header.html
@@ -26,7 +26,7 @@
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                 </button>
-                <a class="navbar-brand" href="home" style="padding: 2px 10px 0px 0px"><img src="image/logo.png" height="40px" width="40px"/><small> Kylin </small></a>
+                <a class="navbar-brand" style="padding: 2px 10px 0px 0px"><img src="image/logo.png" height="40px" width="40px"/><small> Kylin </small></a>
             </div>
 
             <div class="navbar-collapse collapse" collapse="isCollapsed">

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/app/partials/home.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/home.html b/webapp/app/partials/home.html
deleted file mode 100644
index f6c63d0..0000000
--- a/webapp/app/partials/home.html
+++ /dev/null
@@ -1,65 +0,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.
--->
-
-<!--Big Background Image-->
-<div class="bg-holder">
-    <img src="image/Himg.png" />
-</div>
-
-<!--Carousel Part-->
-<div style="height: 442px;">
-    <carousel interval="myInterval">
-        <slide ng-repeat="slide in slides" active="slide.active">
-            <img ng-src="{{slide.image}}" />
-            <div class="carousel-caption">
-                <h1>{{slide.caption}}</h1>
-                <p>{{slide.text}}</p>
-            </div>
-        </slide>
-    </carousel>
-</div>
-
-<!--Features Part-->
-<div id="features" class="container marketing">
-    <div class="row">
-        <div class="col-xs-12 col-sm-4 feature">
-            <a><i class="fa fa-cubes fa-5x"></i></a>
-            <h2>Create Cube</h2>
-            <p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies
-                vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo
-                cursus magna.</p>
-            <p><a class="btn btn-default" href="cubes" role="button">View details »</a></p>
-        </div>
-        <div class="col-xs-12 col-sm-4 feature">
-            <a><i class="fa fa-tasks fa-5x"></i></a>
-            <h2>Query Online</h2>
-            <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras
-                mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris
-                condimentum nibh.</p>
-            <p><a class="btn btn-default" href="query" role="button">View details »</a></p>
-        </div>
-        <div class="col-xs-12 col-sm-4 feature">
-            <a><i class="fa fa-sort-amount-asc fa-5x"></i></a>
-            <h2>Jobs</h2>
-            <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula
-                porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh,
-                ut fermentum massa justo sit amet risus.</p>
-            <p><a class="btn btn-default" href="jobs" role="button">View details »</a></p>
-        </div>
-    </div>
-</div>

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/app/routes.json
----------------------------------------------------------------------
diff --git a/webapp/app/routes.json b/webapp/app/routes.json
index 8a72f09..e13656e 100644
--- a/webapp/app/routes.json
+++ b/webapp/app/routes.json
@@ -1,12 +1,5 @@
 [
     {
-        "url": "/home",
-        "params": {
-            "templateUrl": "partials/home.html",
-            "controller": "IndexCtrl"
-        }
-    },
-    {
         "url": "/cubes",
         "params": {
             "templateUrl": "partials/cubes/cubes.html",
@@ -104,4 +97,4 @@
             "reloadOnSearch": false
         }
     }
-]
\ No newline at end of file
+]

http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/b3b0f2f9/webapp/bower.json
----------------------------------------------------------------------
diff --git a/webapp/bower.json b/webapp/bower.json
index 65c23b8..298cba3 100755
--- a/webapp/bower.json
+++ b/webapp/bower.json
@@ -10,7 +10,7 @@
     "angular-chosen-localytics": "1.0.6",
     "animate.css": "3.0.0",
     "bootstrap": "3.0.0",
-    "font-awesome": "4.0.3",
+    "font-awesome": "4.3.0",
     "angular-ui-ace": "0.1.0",
     "angular-base64": "2.0.1",
     "angular-tree-control": "0.1.4",