Java Code Examples for org.apache.spark.sql.Row#getString()
The following examples show how to use
org.apache.spark.sql.Row#getString() .
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: GroupConcatDistinctUDAF.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
/** * 合并 * update操作,可能是针对一个分组内的部分数据,在某个节点上发生的 * 但是可能一个分组内的数据,会分布在多个节点上处理 * 此时就要用merge操作,将各个节点上分布式拼接好的串,合并起来 */ @Override public void merge(MutableAggregationBuffer buffer1, Row buffer2) { String bufferCityInfo1 = buffer1.getString(0); String bufferCityInfo2 = buffer2.getString(0); for(String cityInfo : bufferCityInfo2.split(",")) { if(!bufferCityInfo1.contains(cityInfo)) { if("".equals(bufferCityInfo1)) { bufferCityInfo1 += cityInfo; } else { bufferCityInfo1 += "," + cityInfo; } } } buffer1.update(0, bufferCityInfo1); }
Example 2
Source File: GroupConcatDistinctUDAF.java From BigDataPlatform with GNU General Public License v3.0 | 6 votes |
/** * 更新 * 可以认为是,一个一个地将组内的字段值传递进来 * 实现拼接的逻辑 */ @Override public void update(MutableAggregationBuffer buffer, Row input) { // 缓冲中的已经拼接过的城市信息串 String bufferCityInfo = buffer.getString(0); // 刚刚传递进来的某个城市信息 String cityInfo = input.getString(0); // 在这里要实现去重的逻辑 // 判断:之前没有拼接过某个城市信息,那么这里才可以接下去拼接新的城市信息 if(!bufferCityInfo.contains(cityInfo)) { if("".equals(bufferCityInfo)) { bufferCityInfo += cityInfo; } else { // 比如1:北京 // 1:北京,2:上海 bufferCityInfo += "," + cityInfo; } buffer.update(0, bufferCityInfo); } }
Example 3
Source File: DummyKafkaOffsetStore.java From envelope with Apache License 2.0 | 6 votes |
@Override public Iterable<Row> getExistingForFilters(Iterable<Row> filters) throws Exception { List<Row> matches = Lists.newArrayList(); for (Row filter : filters) { List<String> filterFieldNames = Lists.newArrayList(filter.schema().fieldNames()); assert (filterFieldNames.get(0).equals("group_id")); assert (filterFieldNames.get(1).equals("topic")); String groupID = filter.getString(0); String topic = filter.getString(1); for (Row row : store.values()) { if (row.getString(0).equals(groupID) && row.getString(1).equals(topic)) { matches.add(row); } } } return matches; }
Example 4
Source File: ProcessStatesAggregationFunction.java From bpmn.ai with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void merge(MutableAggregationBuffer buffer1, Row buffer2) { //TODO: only implemented for ACTIVE and COMPLETED state so far String value = BpmnaiVariables.PROCESS_STATE_ACTIVE; if (!buffer1.isNullAt(0) && !buffer2.isNullAt(0)) { String b1 = buffer1.getString(0); String b2 = buffer2.getString(0); if(b1.equals(BpmnaiVariables.PROCESS_STATE_COMPLETED)){ value = b1; } else { if(b2.equals(BpmnaiVariables.PROCESS_STATE_COMPLETED)) { value = BpmnaiVariables.PROCESS_STATE_COMPLETED; } } } else if(!buffer1.isNullAt(0)){ value = buffer2.getString(0); } else { value = buffer1.getString(0); } buffer1.update(0, value); }
Example 5
Source File: SparkRowConverterTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void testMultiReferenceTypes() { // Row containing the general practitioner from our dataset. Row practitioner = testPatientDataset .select(functions.explode(functions.col("generalpractitioner"))) .select("col.organizationId", "col.practitionerId") .head(); String organizationId = practitioner.getString(0); String practitionerId = practitioner.getString(1); // The reference is not of this type, so the field should be null. Assert.assertNull(organizationId); // The field with the expected prefix should match the original data. Assert.assertEquals(testPatient.getGeneralPractitionerFirstRep().getReference(), "Practitioner/" + practitionerId); Assert.assertEquals(testCondition.getSubject().getReference(), testConditionDecoded.getSubject().getReference()); }
Example 6
Source File: StructureToSecondaryStructureSegments.java From mmtf-spark with Apache License 2.0 | 6 votes |
@Override public Iterator<Row> call(Row t) throws Exception { //get information from the input Row String structureChainId = t.getString(0); String sequence = t.getString(1); String dsspQ8 = t.getString(5); String dsspQ3 = t.getString(6); int numSegments = Math.max(0, sequence.length() - length); List<Row> sequences = new ArrayList<>(numSegments); for (int i = 0; i < sequence.length() - length; i++) { String currSeq = sequence.substring(i, i+length); String labelQ8 = dsspQ8.substring(i + length/2,i + length/2 + 1); String labelQ3 = dsspQ3.substring(i + length/2,i + length/2 + 1); if ( !labelQ8.equals("X") && !labelQ3.equals("X")) { sequences.add( RowFactory.create(structureChainId, currSeq, labelQ8, labelQ3) ); } } return sequences.iterator(); }
Example 7
Source File: DataFrameOps.java From toolbox with Apache License 2.0 | 5 votes |
private static double[] transformRow2DataInstance(Row row, Attributes attributes) throws Exception { double[] instance = new double[row.length()]; for (int i = 0; i < row.length(); i++) { Attribute att = attributes.getFullListOfAttributes().get(i); StateSpaceType space = att.getStateSpaceType(); switch (space.getStateSpaceTypeEnum()) { case REAL: instance[i] = row.getDouble(i); break; case FINITE_SET: String state = row.getString(i); double index = ((FiniteStateSpace) space).getIndexOfState(state); instance[i] = index; break; default: // This should never execute throw new Exception("Unrecognized Error"); } } return instance; }
Example 8
Source File: SQLChar.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public void read(Row row, int ordinal) throws StandardException { if (row.isNullAt(ordinal)) setToNull(); else { isNull = false; value = row.getString(ordinal); } }
Example 9
Source File: TestHelpers.java From iceberg with Apache License 2.0 | 5 votes |
private static Object getPrimitiveValue(Row row, int ord, Type type) { if (row.isNullAt(ord)) { return null; } switch (type.typeId()) { case BOOLEAN: return row.getBoolean(ord); case INTEGER: return row.getInt(ord); case LONG: return row.getLong(ord); case FLOAT: return row.getFloat(ord); case DOUBLE: return row.getDouble(ord); case STRING: return row.getString(ord); case BINARY: case FIXED: case UUID: return row.get(ord); case DATE: return row.getDate(ord); case TIMESTAMP: return row.getTimestamp(ord); case DECIMAL: return row.getDecimal(ord); default: throw new IllegalArgumentException("Unhandled type " + type); } }
Example 10
Source File: StructureToSecondaryStructureElements.java From mmtf-spark with Apache License 2.0 | 5 votes |
@Override public Iterator<Row> call(Row t) throws Exception { // get information from the input Row String sequence = t.getString(1); String dsspQ3 = t.getString(6); int currLength = 0; String currSequence = ""; int j; List<Row> sequences = new ArrayList<>(); for (int i = 0; i < sequence.length(); i++) { currLength = 0; currSequence = ""; for (j = i; j < sequence.length(); j++) { if (dsspQ3.substring(j, j + 1).equals(label)) { currLength++; currSequence = currSequence.concat(sequence.substring(j, j + 1)); } else break; } i += currLength; if (currLength >= minLength) { sequences.add(RowFactory.create(currSequence, label)); } } return sequences.iterator(); }
Example 11
Source File: XML.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
@Override public void read(Row row, int ordinal) throws StandardException { if (row.isNullAt(ordinal)) setToNull(); else xmlStringValue = new SQLChar(row.getString(ordinal)); }
Example 12
Source File: AllButEmptyStringAggregationFunction.java From bpmn.ai with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void merge(MutableAggregationBuffer buffer1, Row buffer2) { String value = ""; if (!buffer1.isNullAt(0) && !buffer2.isNullAt(0)) { String b1 = buffer1.getString(0); String b2 = buffer2.getString(0); value = (b1.equals("") ? b2 : b1); } else if(!buffer1.isNullAt(0)){ value = buffer2.getString(0); } else { value = buffer1.getString(0); } buffer1.update(0, value); }
Example 13
Source File: AllButEmptyStringAggregationFunction.java From bpmn.ai with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void update(MutableAggregationBuffer buffer, Row input) { if (!input.isNullAt(0)) { String currentValue = (buffer.size() == 0 || buffer.getString(0) == null ? "" : buffer.getString(0)); String value = (currentValue.equals("") ? input.getString(0) : currentValue); buffer.update(0, value); } }
Example 14
Source File: TestHelpers.java From iceberg with Apache License 2.0 | 5 votes |
private static Object getPrimitiveValue(Row row, int ord, Type type) { if (row.isNullAt(ord)) { return null; } switch (type.typeId()) { case BOOLEAN: return row.getBoolean(ord); case INTEGER: return row.getInt(ord); case LONG: return row.getLong(ord); case FLOAT: return row.getFloat(ord); case DOUBLE: return row.getDouble(ord); case STRING: return row.getString(ord); case BINARY: case FIXED: case UUID: return row.get(ord); case DATE: return row.getDate(ord); case TIMESTAMP: return row.getTimestamp(ord); case DECIMAL: return row.getDecimal(ord); default: throw new IllegalArgumentException("Unhandled type " + type); } }
Example 15
Source File: AllButEmptyStringAggregationFunction.java From bpmn.ai with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public String evaluate(Row buffer) { return buffer.getString(0); }
Example 16
Source File: Tagger.java From vn.vitk with GNU General Public License v3.0 | 4 votes |
@Override public String call(Row row) throws Exception { return row.getString(columnIndex); }
Example 17
Source File: ProcessStatesAggregationFunction.java From bpmn.ai with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public String evaluate(Row buffer) { return buffer.getString(0); }
Example 18
Source File: BookUrlBuilderApp.java From net.jgp.labs.spark with Apache License 2.0 | 4 votes |
@Override public String call(Row r) throws Exception { String s = "<a href='" + r.getString(4) + "'>" + r.getString(2) + "</a>"; return s; }
Example 19
Source File: DependencyLinkSpanIterator.java From zipkin-dependencies with Apache License 2.0 | 4 votes |
static @Nullable String emptyToNull(Row row, int index) { String result = row.isNullAt(index) ? null : row.getString(index); return result != null && !"".equals(result) ? result : null; }
Example 20
Source File: GroupConcatDistinctUDAF.java From BigDataPlatform with GNU General Public License v3.0 | 4 votes |
@Override public Object evaluate(Row row) { //返回结果 return row.getString(0); }