Source:
<code>private DruidTable computeTable(final String dataSource) { final SegmentMetadataQuery segmentMetadataQuery = new SegmentMetadataQuery( new TableDataSource(dataSource), null, null, false, ImmutableMap.<String, Object>of("useCache", false, "populateCache", false), EnumSet.noneOf(SegmentMetadataQuery.AnalysisType.class), null, true ); final Sequence<SegmentAnalysis> sequence = segmentMetadataQuery.run(walker, Maps.<String, Object>newHashMap()); final List<SegmentAnalysis> results = Sequences.toList(sequence, Lists.<SegmentAnalysis>newArrayList()); if (results.isEmpty()) { return null; } final Map<String, ValueType> columnTypes = Maps.newLinkedHashMap(); String maxSegmentId = ""; for (SegmentAnalysis analysis : results) { for (Map.Entry<String, ColumnAnalysis> entry : analysis.getColumns().entrySet()) { if (entry.getValue().isError()) { continue; } <START> if (!columnTypes.containsKey(entry.getKey()) || analysis.getId().compareTo(maxSegmentId) > 0) { <END> ValueType valueType; try { valueType = ValueType.valueOf(entry.getValue().getType().toUpperCase()); } catch (IllegalArgumentException e) { valueType = ValueType.COMPLEX; } columnTypes.put(entry.getKey(), valueType); } } maxSegmentId = analysis.getId(); } final RowSignature.Builder rowSignature = RowSignature.builder(); for (Map.Entry<String, ValueType> entry : columnTypes.entrySet()) { rowSignature.add(entry.getKey(), entry.getValue()); } return new DruidTable( queryMaker, new TableDataSource(dataSource), rowSignature.build() ); }</code><technical_language>if is a defined contract for segmentID comparison equivalent time interval comparison, compare analysis.getInterval() instead</technical_language>

Target:
private DruidTable computeTable(final String dataSource) { final SegmentMetadataQuery segmentMetadataQuery = new SegmentMetadataQuery( new TableDataSource(dataSource), null, null, false, ImmutableMap.<String, Object>of("useCache", false, "populateCache", false), EnumSet.of(SegmentMetadataQuery.AnalysisType.INTERVAL), null, true ); final Sequence<SegmentAnalysis> sequence = segmentMetadataQuery.run(walker, Maps.<String, Object>newHashMap()); final List<SegmentAnalysis> results = Sequences.toList(sequence, Lists.<SegmentAnalysis>newArrayList()); if (results.isEmpty()) { return null; } final Map<String, ValueType> columnTypes = Maps.newLinkedHashMap(); long maxTimestamp = JodaUtils.MIN_INSTANT; for (SegmentAnalysis analysis : results) { final long timestamp; if (analysis.getIntervals() != null && analysis.getIntervals().size() > 0) { timestamp = analysis.getIntervals().get(analysis.getIntervals().size() - 1).getEndMillis(); } else { timestamp = JodaUtils.MIN_INSTANT; } for (Map.Entry<String, ColumnAnalysis> entry : analysis.getColumns().entrySet()) { if (entry.getValue().isError()) { continue; } if (!columnTypes.containsKey(entry.getKey()) || timestamp >= maxTimestamp) { ValueType valueType; try { valueType = ValueType.valueOf(entry.getValue().getType().toUpperCase()); } catch (IllegalArgumentException e) { valueType = ValueType.COMPLEX; } columnTypes.put(entry.getKey(), valueType); maxTimestamp = timestamp; } } } final RowSignature.Builder rowSignature = RowSignature.builder(); for (Map.Entry<String, ValueType> entry : columnTypes.entrySet()) { rowSignature.add(entry.getKey(), entry.getValue()); } return new DruidTable( queryMaker, new TableDataSource(dataSource), rowSignature.build() ); }