Source:
<code>public static Dataset<Row> resultSetToDF(ResultSet rs) throws StandardException { EmbedResultSet40 ers = (EmbedResultSet40) rs; com.splicemachine.db.iapi.sql.ResultSet serverSideResultSet = ers.getUnderlyingResultSet(); SpliceBaseOperation operation = (SpliceBaseOperation) serverSideResultSet; DataSetProcessor dsp = EngineDriver.driver().processorFactory().distributedProcessor(); DataSet<ExecRow> spliceDataSet = operation.getResultDataSet(dsp); final ResultColumnDescriptor[] columns = serverSideResultSet.getResultDescription().getColumnInfo(); List<StructField> fields = new ArrayList<>(); for (ResultColumnDescriptor column : columns) { fields.add(column.getStructField()); } <START> if( fields.stream().map( f -> f.name().toUpperCase() ).distinct().count() != fields.size() ) { END> fields = new ArrayList<>(); Set<String> used = new HashSet<>(); for (ResultColumnDescriptor column : columns) { int i = 0; String fullname = column.getSourceSchemaName()+"."+column.getSourceTableName()+"."+column.getName(); String name = fullname; while( used.contains(name) ) { i += 1; name = fullname+"_"+i; } used.add(name); StructField sf = column.getStructField(); fields.add(new StructField(name, sf.dataType(), sf.nullable(), sf.metadata())); } } StructType schema = DataTypes.createStructType(fields); if(spliceDataSet instanceof SparkDataSet) { JavaRDD<ExecRow> rdd = ((SparkDataSet)spliceDataSet).rdd; return SpliceSpark.getSession().createDataFrame(rdd.map(new LocatedRowToRowFunction()), schema); } else { return ((NativeSparkDataSet) spliceDataSet).dataset.toDF( schema.fieldNames() ); } }</code><technical_language>Do need toUpperCase() here? consistent subsequent HashSet logic, honors case sensitivity</technical_language>

Target:
public static Dataset<Row> resultSetToDF(ResultSet rs) throws StandardException { EmbedResultSet40 ers = (EmbedResultSet40) rs; com.splicemachine.db.iapi.sql.ResultSet serverSideResultSet = ers.getUnderlyingResultSet(); SpliceBaseOperation operation = (SpliceBaseOperation) serverSideResultSet; DataSetProcessor dsp = EngineDriver.driver().processorFactory().distributedProcessor(); DataSet<ExecRow> spliceDataSet = operation.getResultDataSet(dsp); final ResultColumnDescriptor[] columns = serverSideResultSet.getResultDescription().getColumnInfo(); List<StructField> fields = new ArrayList<>(); for (ResultColumnDescriptor column : columns) { fields.add(column.getStructField()); } if( fields.stream().map( f -> f.name() ).distinct().count() != fields.size() ) { fields = new ArrayList<>(); Set<String> used = new HashSet<>(); for (ResultColumnDescriptor column : columns) { int i = 0; String fullname = column.getSourceSchemaName()+"."+column.getSourceTableName()+"."+column.getName(); String name = fullname; while( used.contains(name) ) { i += 1; name = fullname+"_"+i; } used.add(name); StructField sf = column.getStructField(); fields.add(new StructField(name, sf.dataType(), sf.nullable(), sf.metadata())); } } StructType schema = DataTypes.createStructType(fields); if(spliceDataSet instanceof SparkDataSet) { JavaRDD<ExecRow> rdd = ((SparkDataSet)spliceDataSet).rdd; return SpliceSpark.getSession().createDataFrame(rdd.map(new LocatedRowToRowFunction()), schema); } else { return ((NativeSparkDataSet) spliceDataSet).dataset.toDF( schema.fieldNames() ); } }