Java Code Examples for org.apache.kylin.metadata.model.PartitionDesc#getPartitionTimeColumnRef()
The following examples show how to use
org.apache.kylin.metadata.model.PartitionDesc#getPartitionTimeColumnRef() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyValueBuilder.java From kylin with Apache License 2.0 | 6 votes |
/** * Use the segment start time as the map key, the time unit depends on the partition columns * If the partition_time_column is null, the unit is day; * otherwise, the unit is second */ private String getSegmentStartTime(CubeSegment segment) { long startTime = segment.getTSRange().start.v; DataModelDesc model = segment.getModel(); PartitionDesc partitionDesc = model.getPartitionDesc(); if (partitionDesc == null || !partitionDesc.isPartitioned()) { return "0"; } else if (partitionDesc.partitionColumnIsTimeMillis()) { return "" + startTime; } else if (partitionDesc.getPartitionTimeColumnRef() != null) { return "" + startTime / 1000L; } else if (partitionDesc.getPartitionDateColumnRef() != null) { return "" + startTime / 86400000L; } return "0"; }
Example 2
Source File: JdbcHiveInputBase.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
protected AbstractExecutable createSqoopToFlatHiveStep(String jobWorkingDir, String cubeName) { KylinConfig config = getConfig(); PartitionDesc partitionDesc = flatDesc.getDataModel().getPartitionDesc(); String partCol = null; if (partitionDesc.isPartitioned()) { partCol = partitionDesc.getPartitionDateColumn();//tablename.colname } String splitTableAlias; String splitColumn; String splitDatabase; TblColRef splitColRef = determineSplitColumn(); splitTableAlias = splitColRef.getTableAlias(); splitColumn = getColumnIdentityQuoted(splitColRef, jdbcMetadataDialect, metaMap, true); splitDatabase = splitColRef.getColumnDesc().getTable().getDatabase(); String selectSql = generateSelectDataStatementRDBMS(flatDesc, true, new String[] { partCol }, jdbcMetadataDialect, metaMap); selectSql = escapeQuotationInSql(selectSql); String hiveTable = flatDesc.getTableName(); String connectionUrl = config.getJdbcSourceConnectionUrl(); String driverClass = config.getJdbcSourceDriver(); String jdbcUser = config.getJdbcSourceUser(); String jdbcPass = config.getJdbcSourcePass(); String sqoopHome = config.getSqoopHome(); String sqoopNullString = config.getSqoopNullString(); String sqoopNullNonString = config.getSqoopNullNonString(); String filedDelimiter = config.getJdbcSourceFieldDelimiter(); int mapperNum = config.getSqoopMapperNum(); String bquery = String.format(Locale.ROOT, "SELECT min(%s), max(%s) FROM %s.%s ", splitColumn, splitColumn, getSchemaQuoted(metaMap, splitDatabase, jdbcMetadataDialect, true), getTableIdentityQuoted(splitColRef.getTableRef(), metaMap, jdbcMetadataDialect, true)); if (partitionDesc.isPartitioned()) { SegmentRange segRange = flatDesc.getSegRange(); if (segRange != null && !segRange.isInfinite()) { if (partitionDesc.getPartitionDateColumnRef().getTableAlias().equals(splitTableAlias) && (partitionDesc.getPartitionTimeColumnRef() == null || partitionDesc .getPartitionTimeColumnRef().getTableAlias().equals(splitTableAlias))) { String quotedPartCond = partitionDesc.getPartitionConditionBuilder().buildDateRangeCondition( partitionDesc, flatDesc.getSegment(), segRange, col -> getTableColumnIdentityQuoted(col, jdbcMetadataDialect, metaMap, true)); bquery += " WHERE " + quotedPartCond; } } } bquery = escapeQuotationInSql(bquery); // escape ` in cmd splitColumn = escapeQuotationInSql(splitColumn); String cmd = String.format(Locale.ROOT, "%s/bin/sqoop import" + generateSqoopConfigArgString() + "--connect \"%s\" --driver %s --username %s --password \"%s\" --query \"%s AND \\$CONDITIONS\" " + "--target-dir %s/%s --split-by %s --boundary-query \"%s\" --null-string '%s' " + "--null-non-string '%s' --fields-terminated-by '%s' --num-mappers %d", sqoopHome, connectionUrl, driverClass, jdbcUser, jdbcPass, selectSql, jobWorkingDir, hiveTable, splitColumn, bquery, sqoopNullString, sqoopNullNonString, filedDelimiter, mapperNum); logger.debug("sqoop cmd : {}", cmd); CmdStep step = new CmdStep(); step.setCmd(cmd); step.setName(ExecutableConstants.STEP_NAME_SQOOP_TO_FLAT_HIVE_TABLE); return step; }
Example 3
Source File: JdbcHiveInputBase.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override protected AbstractExecutable createSqoopToFlatHiveStep(String jobWorkingDir, String cubeName) { KylinConfig config = flatDesc.getDataModel().getConfig(); PartitionDesc partitionDesc = flatDesc.getDataModel().getPartitionDesc(); String partCol = null; boolean enableQuote = dataSource.getSqlConverter().getConfigurer().enableQuote(); SqlDialect sqlDialect = enableQuote ? dataSource.getSqlConverter().getConfigurer().getSqlDialect() : FlatTableSqlQuoteUtils.NON_QUOTE_DIALECT; SqlConverter.IConfigurer iconfigurer = dataSource.getSqlConverter().getConfigurer(); if (partitionDesc.isPartitioned()) { partCol = partitionDesc.getPartitionDateColumn(); //tablename.colname } String splitTable; String splitTableAlias; String splitColumn; String splitDatabase; TblColRef splitColRef = determineSplitColumn(); splitTable = splitColRef.getTableRef().getTableDesc().getName(); splitTableAlias = splitColRef.getTableAlias(); splitDatabase = splitColRef.getColumnDesc().getTable().getDatabase(); if (enableQuote) { splitColumn = sqlDialect.quoteIdentifier(splitColRef.getTableAlias()) + "." + sqlDialect.quoteIdentifier(splitColRef.getName()); splitDatabase = sqlDialect.quoteIdentifier(splitDatabase); splitTable = sqlDialect.quoteIdentifier(splitTable); splitTableAlias = sqlDialect.quoteIdentifier(splitTableAlias); } else { splitColumn = splitColRef.getTableAlias() + "." + splitColRef.getName(); } String selectSql = JoinedFlatTable.generateSelectDataStatement(flatDesc, true, new String[]{partCol}, sqlDialect); selectSql = escapeQuotationInSql(dataSource.convertSql(selectSql)); String hiveTable = flatDesc.getTableName(); String filedDelimiter = config.getJdbcSourceFieldDelimiter(); int mapperNum = config.getSqoopMapperNum(); String bquery; bquery = String.format(Locale.ROOT, "SELECT min(%s), max(%s) FROM %s.%s as %s", splitColumn, splitColumn, splitDatabase, splitTable, splitTableAlias); bquery = dataSource.convertSql(bquery); if (partitionDesc.isPartitioned()) { SegmentRange segRange = flatDesc.getSegRange(); if (segRange != null && !segRange.isInfinite()) { if (partitionDesc.getPartitionDateColumnRef().getTableAlias().equals(splitTableAlias) && (partitionDesc.getPartitionTimeColumnRef() == null || partitionDesc .getPartitionTimeColumnRef().getTableAlias().equals(splitTableAlias))) { String quotedPartCond = FlatTableSqlQuoteUtils.quoteIdentifierInSqlExpr(flatDesc, partitionDesc.getPartitionConditionBuilder().buildDateRangeCondition(partitionDesc, flatDesc.getSegment(), segRange, null), sqlDialect); bquery += " WHERE " + quotedPartCond; } } } bquery = escapeQuotationInSql(bquery); splitColumn = escapeQuotationInSql(splitColumn); String cmd = StringUtils.format( "--connect \"%s\" --driver \"%s\" --username \"%s\" --password \"%s\" --query \"%s AND \\$CONDITIONS\" " + "--target-dir \"%s/%s\" --split-by \"%s\" --boundary-query \"%s\" --null-string '' " + "--fields-terminated-by '%s' --num-mappers %d", dataSource.getJdbcUrl(), dataSource.getJdbcDriver(), dataSource.getJdbcUser(), dataSource.getJdbcPassword(), selectSql, jobWorkingDir, hiveTable, splitColumn, bquery, filedDelimiter, mapperNum); if (iconfigurer.getTransactionIsolationLevel() != null) { cmd = cmd + " --relaxed-isolation --metadata-transaction-isolation-level " + iconfigurer.getTransactionIsolationLevel(); } logger.debug("sqoop cmd: {}", cmd); SqoopCmdStep step = new SqoopCmdStep(); step.setCmd(cmd); step.setName(ExecutableConstants.STEP_NAME_SQOOP_TO_FLAT_HIVE_TABLE); return step; }
Example 4
Source File: JdbcHiveInputBase.java From kylin with Apache License 2.0 | 4 votes |
protected AbstractExecutable createSqoopToFlatHiveStep(String jobWorkingDir, String cubeName) { KylinConfig config = getConfig(); PartitionDesc partitionDesc = flatDesc.getDataModel().getPartitionDesc(); String partCol = null; if (partitionDesc.isPartitioned()) { partCol = partitionDesc.getPartitionDateColumn();//tablename.colname } String splitTableAlias; String splitColumn; String splitDatabase; TblColRef splitColRef = determineSplitColumn(); splitTableAlias = splitColRef.getTableAlias(); splitColumn = getColumnIdentityQuoted(splitColRef, jdbcMetadataDialect, metaMap, true); splitDatabase = splitColRef.getColumnDesc().getTable().getDatabase(); String selectSql = generateSelectDataStatementRDBMS(flatDesc, true, new String[] { partCol }, jdbcMetadataDialect, metaMap); selectSql = escapeQuotationInSql(selectSql); String hiveTable = flatDesc.getTableName(); String connectionUrl = config.getJdbcSourceConnectionUrl(); String driverClass = config.getJdbcSourceDriver(); String jdbcUser = config.getJdbcSourceUser(); String jdbcPass = config.getJdbcSourcePass(); String sqoopHome = config.getSqoopHome(); String sqoopNullString = config.getSqoopNullString(); String sqoopNullNonString = config.getSqoopNullNonString(); String filedDelimiter = config.getJdbcSourceFieldDelimiter(); int mapperNum = config.getSqoopMapperNum(); String bquery = String.format(Locale.ROOT, "SELECT min(%s), max(%s) FROM %s.%s ", splitColumn, splitColumn, getSchemaQuoted(metaMap, splitDatabase, jdbcMetadataDialect, true), getTableIdentityQuoted(splitColRef.getTableRef(), metaMap, jdbcMetadataDialect, true)); if (partitionDesc.isPartitioned()) { SegmentRange segRange = flatDesc.getSegRange(); if (segRange != null && !segRange.isInfinite()) { if (partitionDesc.getPartitionDateColumnRef().getTableAlias().equals(splitTableAlias) && (partitionDesc.getPartitionTimeColumnRef() == null || partitionDesc .getPartitionTimeColumnRef().getTableAlias().equals(splitTableAlias))) { String quotedPartCond = partitionDesc.getPartitionConditionBuilder().buildDateRangeCondition( partitionDesc, flatDesc.getSegment(), segRange, col -> getTableColumnIdentityQuoted(col, jdbcMetadataDialect, metaMap, true)); bquery += " WHERE " + quotedPartCond; } } } bquery = escapeQuotationInSql(bquery); // escape ` in cmd splitColumn = escapeQuotationInSql(splitColumn); String cmd = String.format(Locale.ROOT, "%s/bin/sqoop import" + generateSqoopConfigArgString() + "--connect \"%s\" --driver %s --username %s --password \"%s\" --query \"%s AND \\$CONDITIONS\" " + "--target-dir %s/%s --split-by %s --boundary-query \"%s\" --null-string '%s' " + "--null-non-string '%s' --fields-terminated-by '%s' --num-mappers %d", sqoopHome, connectionUrl, driverClass, jdbcUser, jdbcPass, selectSql, jobWorkingDir, hiveTable, splitColumn, bquery, sqoopNullString, sqoopNullNonString, filedDelimiter, mapperNum); logger.debug("sqoop cmd : {}", cmd); CmdStep step = new CmdStep(); step.setCmd(cmd); step.setName(ExecutableConstants.STEP_NAME_SQOOP_TO_FLAT_HIVE_TABLE); return step; }
Example 5
Source File: JdbcHiveInputBase.java From kylin with Apache License 2.0 | 4 votes |
@Override protected AbstractExecutable createSqoopToFlatHiveStep(String jobWorkingDir, String cubeName) { KylinConfig config = flatDesc.getDataModel().getConfig(); PartitionDesc partitionDesc = flatDesc.getDataModel().getPartitionDesc(); String partCol = null; boolean enableQuote = dataSource.getSqlConverter().getConfigurer().enableQuote(); enableQuote = enableQuote && config.enableHiveDdlQuote(); logger.debug("Quote switch is set to {}", enableQuote); SqlDialect sqlDialect = enableQuote ? dataSource.getSqlConverter().getConfigurer().getSqlDialect() : FlatTableSqlQuoteUtils.NON_QUOTE_DIALECT; SqlConverter.IConfigurer iconfigurer = dataSource.getSqlConverter().getConfigurer(); if (partitionDesc.isPartitioned()) { partCol = partitionDesc.getPartitionDateColumn(); //tablename.colname } String splitTable; String splitTableAlias; String splitColumn; String splitDatabase; TblColRef splitColRef = determineSplitColumn(); splitTable = splitColRef.getTableRef().getTableDesc().getName(); splitTableAlias = splitColRef.getTableAlias(); splitDatabase = splitColRef.getColumnDesc().getTable().getDatabase(); if (enableQuote) { splitColumn = sqlDialect.quoteIdentifier(splitColRef.getTableAlias()) + "." + sqlDialect.quoteIdentifier(splitColRef.getName()); splitDatabase = sqlDialect.quoteIdentifier(splitDatabase); splitTable = sqlDialect.quoteIdentifier(splitTable); splitTableAlias = sqlDialect.quoteIdentifier(splitTableAlias); } else { splitColumn = splitColRef.getTableAlias() + "." + splitColRef.getName(); } String selectSql = JoinedFlatTable.generateSelectDataStatement(flatDesc, true, new String[]{partCol}, sqlDialect); selectSql = escapeQuotationInSql(dataSource.convertSql(selectSql)); String hiveTable = flatDesc.getTableName(); String filedDelimiter = config.getJdbcSourceFieldDelimiter(); int mapperNum = config.getSqoopMapperNum(); String bquery; bquery = String.format(Locale.ROOT, "SELECT min(%s), max(%s) FROM %s.%s as %s", splitColumn, splitColumn, splitDatabase, splitTable, splitTableAlias); bquery = dataSource.convertSql(bquery); if (partitionDesc.isPartitioned()) { SegmentRange segRange = flatDesc.getSegRange(); if (segRange != null && !segRange.isInfinite()) { if (partitionDesc.getPartitionDateColumnRef().getTableAlias().equals(splitTableAlias) && (partitionDesc.getPartitionTimeColumnRef() == null || partitionDesc .getPartitionTimeColumnRef().getTableAlias().equals(splitTableAlias))) { String quotedPartCond = FlatTableSqlQuoteUtils.quoteIdentifierInSqlExpr(flatDesc, partitionDesc.getPartitionConditionBuilder().buildDateRangeCondition(partitionDesc, flatDesc.getSegment(), segRange, null), sqlDialect); bquery += " WHERE " + quotedPartCond; } } } bquery = escapeQuotationInSql(bquery); splitColumn = escapeQuotationInSql(splitColumn); String cmd = StringUtils.format( "--connect \"%s\" --driver \"%s\" --username \"%s\" --password \"%s\" --query \"%s AND \\$CONDITIONS\" " + "--target-dir \"%s/%s\" --split-by \"%s\" --boundary-query \"%s\" --null-string '' " + "--fields-terminated-by '%s' --num-mappers %d", dataSource.getJdbcUrl(), dataSource.getJdbcDriver(), dataSource.getJdbcUser(), dataSource.getJdbcPassword(), selectSql, jobWorkingDir, hiveTable, splitColumn, bquery, filedDelimiter, mapperNum); if (iconfigurer.getTransactionIsolationLevel() != null) { cmd = cmd + " --relaxed-isolation --metadata-transaction-isolation-level " + iconfigurer.getTransactionIsolationLevel(); } logger.debug("sqoop cmd: {}", cmd); SqoopCmdStep step = new SqoopCmdStep(); step.setCmd(cmd); step.setName(ExecutableConstants.STEP_NAME_SQOOP_TO_FLAT_HIVE_TABLE); return step; }
Example 6
Source File: TableSchemaUpdater.java From kylin with Apache License 2.0 | 4 votes |
public static DataModelDesc dealWithMappingForModel(DataModelDesc other, Map<String, TableSchemaUpdateMapping> mappings) { // For filter condition, not support if (!Strings.isNullOrEmpty(other.getFilterCondition())) { throw new UnsupportedOperationException("Cannot deal with filter condition " + other.getFilterCondition()); } DataModelDesc copy = DataModelDesc.getCopyOf(other); copy.setLastModified(other.getLastModified()); // mapping for root fact table identity TableSchemaUpdateMapping rootMapping = getTableSchemaUpdateMapping(mappings, other.getRootFactTableName()); if (rootMapping != null) { TableDesc rootFactTable = other.getRootFactTable().getTableDesc(); copy.setRootFactTableName( rootMapping.getTableIdentity(rootFactTable.getDatabase(), rootFactTable.getName())); } // mapping for joins JoinTableDesc[] joinTables = other.getJoinTables(); JoinTableDesc[] joinTablesCopy = new JoinTableDesc[joinTables.length]; for (int i = 0; i < joinTables.length; i++) { JoinTableDesc joinTable = joinTables[i]; joinTablesCopy[i] = JoinTableDesc.getCopyOf(joinTable); String tableIdentity = joinTable.getTable(); TableSchemaUpdateMapping mapping = getTableSchemaUpdateMapping(mappings, tableIdentity); if (mapping != null && mapping.isTableIdentityChanged()) { joinTablesCopy[i].setTable(mapping.getTableIdentity(tableIdentity)); } } copy.setJoinTables(joinTablesCopy); // mapping for partition columns PartitionDesc partDesc = other.getPartitionDesc(); PartitionDesc partCopy = PartitionDesc.getCopyOf(partDesc); if (partDesc.getPartitionDateColumnRef() != null) { partCopy.setPartitionDateColumn( replacePartitionCol(partDesc.getPartitionDateColumnRef().getCanonicalName(), mappings)); } if (partDesc.getPartitionTimeColumnRef() != null) { partCopy.setPartitionTimeColumn( replacePartitionCol(partDesc.getPartitionTimeColumnRef().getCanonicalName(), mappings)); } copy.setPartitionDesc(partCopy); return copy; }