public TblColRef findColumnRef(String table, String column) { return model.findColumn(table, column); }
void init(CubeDesc cubeDesc) { DataModelDesc model = cubeDesc.getModel(); column = column.toUpperCase(Locale.ROOT); colRef = model.findColumn(column); if (reuseColumn != null) { reuseColumn = reuseColumn.toUpperCase(Locale.ROOT); reuseColRef = model.findColumn(reuseColumn); } }
public void init(DataModelDesc model) { if (StringUtils.isEmpty(partitionDateColumn)) return; partitionDateColumnRef = model.findColumn(partitionDateColumn); partitionDateColumn = partitionDateColumnRef.getIdentity(); if (StringUtils.isBlank(partitionTimeColumn) == false) { partitionTimeColumnRef = model.findColumn(partitionTimeColumn); partitionTimeColumn = partitionTimeColumnRef.getIdentity(); } partitionConditionBuilder = (IPartitionConditionBuilder) ClassUtil.newInstance(partitionConditionBuilderClz); }
private void normalizeColumnNames(String[] names) { if (names == null) return; for (int i = 0; i < names.length; i++) { TblColRef col = cubeDesc.getModel().findColumn(names[i]); names[i] = col.getIdentity(); } // check no dup Set<String> set = new HashSet<>(Arrays.asList(names)); if (set.size() < names.length) throw new IllegalStateException( "Columns in aggrgroup must not contain duplication: " + Arrays.asList(names)); }
private void buildPartialCubeFullMask(RowKeyDesc rowKeyDesc) { Preconditions.checkState(this.includes != null); Preconditions.checkState(this.includes.length != 0); partialCubeFullMask = 0L; for (String dim : this.includes) { TblColRef hColumn = cubeDesc.getModel().findColumn(dim); Integer index = rowKeyDesc.getColumnBitIndex(hColumn); long bit = 1L << index; partialCubeFullMask |= bit; } }
public TblColRef findColumn(String column) throws IllegalArgumentException { TblColRef result = null; String input = column; column = column.toUpperCase(Locale.ROOT); int cut = column.lastIndexOf('.'); if (cut > 0) { // table specified result = findColumn(column.substring(0, cut), column.substring(cut + 1)); } else { // table not specified, try each table for (TableRef tableRef : allTableRefs) { result = tableRef.getColumn(column); if (result != null) break; } } if (result == null) throw new IllegalArgumentException("Column not found by " + input); return result; }
/** * @param context * @param cube * @param value */ private void validateColumnParameter(ValidateContext context, CubeDesc cube, String value) { DataModelDesc model = cube.getModel(); try { model.findColumn(value); } catch (IllegalArgumentException e) { context.addResult(ResultLevel.ERROR, e.getMessage()); } }
private void buildMandatoryColumnMask(RowKeyDesc rowKeyDesc) { mandatoryColumnMask = 0L; String[] mandatory_dims = this.selectRule.mandatoryDims; if (mandatory_dims == null || mandatory_dims.length == 0) { return; } for (String dim : mandatory_dims) { TblColRef hColumn = cubeDesc.getModel().findColumn(dim); Integer index = rowKeyDesc.getColumnBitIndex(hColumn); mandatoryColumnMask |= (1L << index); } }
public List<TblColRef> buildGroups() { List<TblColRef> groups = new ArrayList<TblColRef>(); TblColRef c1 = model.findColumn("DEFAULT.TEST_KYLIN_FACT.CAL_DT"); groups.add(c1); TblColRef c2 = model.findColumn("DEFAULT.TEST_CATEGORY_GROUPINGS.META_CATEG_NAME"); groups.add(c2); return groups; }
private void initDimensionsAndMetrics() { for (ModelDimensionDesc dim : dimensions) { dim.init(this); } for (int i = 0; i < metrics.length; i++) { metrics[i] = findColumn(metrics[i]).getIdentity(); } }
public Set<Long> generateMandatoryCuboids(List<Set<String>> mandatoryDimensionSetList) { Map<String, RowKeyColDesc> rowKeyColDescMap = Maps.newHashMap(); for (RowKeyColDesc entry : getRowkey().getRowKeyColumns()) { rowKeyColDescMap.put(entry.getColumn(), entry); } Set<Long> mandatoryCuboids = Sets.newHashSetWithExpectedSize(mandatoryDimensionSetList.size()); for (Set<String> mandatoryDimensionSet : mandatoryDimensionSetList) { long cuboid = 0L; for (String columnName : mandatoryDimensionSet) { TblColRef tblColRef = model.findColumn(columnName); RowKeyColDesc rowKeyColDesc = rowKeyColDescMap.get(tblColRef.getIdentity()); // check if mandatory dimension set list is valid if (rowKeyColDesc == null) { logger.warn("Column " + columnName + " in " + mandatoryDimensionSet + " does not exist"); throw new IllegalStateException( "Column " + columnName + " in " + mandatoryDimensionSet + " does not exist"); } cuboid |= 1L << rowKeyColDesc.getBitIndex(); } mandatoryCuboids.add(cuboid); } return mandatoryCuboids; }
private boolean validate() { // ensure no dup between dimensions/metrics for (ModelDimensionDesc dim : dimensions) { String table = dim.getTable(); for (String c : dim.getColumns()) { TblColRef dcol = findColumn(table, c); metrics = ArrayUtils.removeElement(metrics, dcol.getIdentity()); } } Set<TblColRef> mcols = new HashSet<>(); for (String m : metrics) { mcols.add(findColumn(m)); } // validate PK/FK are in dimensions boolean pkfkDimAmended = false; for (Chain chain : joinsTree.getTableChains().values()) { pkfkDimAmended = validatePkFkDim(chain.join, mcols) || pkfkDimAmended; } return pkfkDimAmended; }
public List<FunctionDesc> buildAggregations1() { List<FunctionDesc> functions = new ArrayList<FunctionDesc>(); TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACTPRICE"); FunctionDesc f1 = FunctionDesc.newInstance("SUM", // ParameterDesc.newInstance(priceCol), "decimal(19,4)"); functions.add(f1); return functions; }
public List<FunctionDesc> buildAggregations() { List<FunctionDesc> functions = new ArrayList<FunctionDesc>(); TblColRef priceCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.PRICE"); TblColRef sellerCol = model.findColumn("DEFAULT.TEST_KYLIN_FACT.SELLER_ID"); FunctionDesc f1 = FunctionDesc.newInstance("SUM", // ParameterDesc.newInstance(priceCol), "decimal(19,4)"); functions.add(f1); FunctionDesc f2 = FunctionDesc.newInstance("COUNT_DISTINCT", // ParameterDesc.newInstance(sellerCol), "hllc(10)"); functions.add(f2); return functions; }
public void init(DataModelDesc model) { expression = expression.toUpperCase(Locale.ROOT); if (expression.equals(PercentileMeasureType.FUNC_PERCENTILE)) { expression = PercentileMeasureType.FUNC_PERCENTILE_APPROX; // for backward compatibility } returnDataType = DataType.getType(returnType); for (ParameterDesc p = parameter; p != null; p = p.getNextParameter()) { if (p.isColumnType()) { TblColRef colRef = model.findColumn(p.getValue()); p.setValue(colRef.getIdentity()); p.setColRef(colRef); } } }
void init(DataModelDesc model) { table = table.toUpperCase(Locale.ROOT); if (columns != null) { StringUtil.toUpperCaseArray(columns, columns); } if (model != null) { table = model.findTable(table).getAlias(); if (columns != null) { for (int i = 0; i < columns.length; i++) { TblColRef column = model.findColumn(table, columns[i]); if (column.getColumnDesc().isComputedColumn() && !model.isFactTable(column.getTableRef())) { throw new RuntimeException("Computed Column on lookup table is not allowed"); } columns[i] = column.getName(); } } } }
private TblColRef initDimensionColRef(DimensionDesc dim, String colName) { TblColRef col = model.findColumn(dim.getTable(), colName); // for backward compatibility if (KylinVersion.isBefore200(getVersion())) { // 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(), col); if (idx >= 0) { col = join.getForeignKeyColumns()[idx]; } } } return initDimensionColRef(col); }
private void assertSnowflakeQuality(DataModelDesc model) { Assert.assertNotNull(model); try { model.findTable("TEST_COUNTRY"); Assert.fail(); } catch (IllegalArgumentException ex) { // excepted } Assert.assertNotNull(model.findTable("BUYER_COUNTRY")); Assert.assertNotNull(model.findTable("SELLER_COUNTRY")); Assert.assertNotNull(model.findColumn("BUYER_COUNTRY.NAME")); Assert.assertNotNull(model.findColumn("BUYER_ID")); }
@Test public void testNoDupColInDimAndMeasure() { DataModelDesc model = DataModelManager.getInstance(getTestConfig()).getDataModelDesc("test_kylin_inner_join_model_desc"); String[] metrics = model.getMetrics(); TblColRef col = model.findColumn("edw.test_cal_dt.cal_dt"); assertTrue(metrics.length == 2); assertTrue(ArrayUtils.contains(metrics, col.getIdentity()) == false); }
@Test public void testEmptySegment() { CubeSegment seg = cube.getFirstSegment(); TblColRef col = cube.getModel().findColumn("CUSTOMER.C_NATION"); // a normal hit TupleFilter f = compare(col, FilterOperatorEnum.EQ, "CHINA"); SegmentPruner segmentPruner = new SegmentPruner(f); Assert.assertTrue(segmentPruner.check(seg)); // make the segment empty, it should be pruned seg.setInputRecords(0); Assert.assertFalse(segmentPruner.check(seg)); }