@Test(dataProvider = "getBoundTypes") public void testBetweenBoundTypes(String startBoundType, String endBoundType) throws LensException { String whereClause = getTimerangeWriter().getTimeRangeWhereClause(getMockedCubeContextForBounds(startBoundType, endBoundType), "test", answeringParts); int testStartOffset = START_DATE_OFFSET; int testEndOffset = END_DATE_OFFSET; if (startBoundType.equalsIgnoreCase(OPEN)) { testStartOffset = START_DATE_OFFSET - 1; } if (endBoundType.equalsIgnoreCase(OPEN)) { testEndOffset = END_DATE_OFFSET + 1; } validateBetweenBoundTypes(whereClause, null, testStartOffset, testEndOffset); whereClause = getTimerangeWriter().getTimeRangeWhereClause(getMockedCubeContextForBounds(startBoundType, endBoundType), "test", answeringPartsWithFormat); validateBetweenBoundTypes(whereClause, DAY_DB_FORMAT, testStartOffset, testEndOffset); }
@Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; } boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean(CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()).append("') "); } return partStr.toString(); }
BetweenTimeRangeWriter implements TimeRangeWriter { @Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; } boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean(CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()).append("') "); } return partStr.toString(); } }
BetweenTimeRangeWriter implements TimeRangeWriter { @Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; } boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean(CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()).append("') "); } return partStr.toString(); }  }
BetweenTimeRangeWriter implements TimeRangeWriter { @Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; } boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean(CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()).append("') "); } return partStr.toString(); }  @Override String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName,
    Set<FactPartition> rangeParts); }
BetweenTimeRangeWriter implements TimeRangeWriter { @Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; } boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean(CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()).append("') "); } return partStr.toString(); }  @Override String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName,
    Set<FactPartition> rangeParts);  }