Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.source.hive;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.lock.DistributedLock;
import org.apache.kylin.common.util.HiveCmdBuilder;
import org.apache.kylin.common.util.Pair;
import org.apache.kylin.cube.CubeInstance;
import org.apache.kylin.cube.CubeManager;
import org.apache.kylin.engine.mr.steps.CubingExecutableUtil;
import org.apache.kylin.job.common.PatternedLogger;
import org.apache.kylin.job.exception.ExecuteException;
import org.apache.kylin.job.execution.AbstractExecutable;
import org.apache.kylin.job.execution.ExecutableContext;
import org.apache.kylin.job.execution.ExecuteResult;
import org.apache.kylin.metadata.model.IEngineAware;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
*
*/
public class CreateMrHiveDictStep extends AbstractExecutable {
private static final Logger logger = LoggerFactory.getLogger(CreateMrHiveDictStep.class);
private final PatternedLogger stepLogger = new PatternedLogger(logger);
private DistributedLock lock = KylinConfig.getInstanceFromEnv().getDistributedLockFactory().lockForCurrentThread();
private static final String GET_SQL = "\" Get Max Dict Value Sql : \"";
protected void createMrHiveDict(KylinConfig config) throws Exception {
try {
if (getIsLock()) {
String pathName = getLockPathName();
if (Strings.isNullOrEmpty(pathName)) {
throw new IllegalArgumentException("create Mr-Hive dict lock path name is null");
}
String lockPath = getLockPath(pathName);
boolean isLocked = true;
long lockStartTime = System.currentTimeMillis();
while (isLocked) {
isLocked = lock.isLocked(lockPath);
stepLogger.log("zookeeper lock path :" + lockPath + ", result is " + isLocked);
if (!isLocked) {
break;
}
// wait 1 min and try again
Thread.sleep(60000);
}
stepLogger.log("zookeeper get lock costTime : " + ((System.currentTimeMillis() - lockStartTime) / 1000) + " s");
lock.lock(lockPath);
}
final HiveCmdBuilder hiveCmdBuilder = new HiveCmdBuilder(getName());
hiveCmdBuilder.overwriteHiveProps(config.getHiveConfigOverride());
hiveCmdBuilder.addStatement(getInitStatement());
String sql = getCreateTableStatement();
if (sql != null && sql.length() > 0) {
hiveCmdBuilder.addStatement(sql);
}
Map maxDictValMap = deserilizeForMap(getMaxDictStatementMap());
Map dictSqlMap = deserilizeForMap(getCreateTableStatementMap());
if (dictSqlMap != null && dictSqlMap.size() > 0) {
IHiveClient hiveClient = HiveClientFactory.getHiveClient();
if (maxDictValMap != null && maxDictValMap.size() > 0) {
if (maxDictValMap.size() == dictSqlMap.size()) {
maxDictValMap.forEach((columnName, maxDictValSql) -> {
int max = 0;
List