Skip to content

Commit

Permalink
Add getSchema() to GenericRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
abcfy2 committed Dec 7, 2024
1 parent 5e304cb commit bd363cf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.clickhouse.client.api.data_formats.internal;

import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
import com.clickhouse.client.api.metadata.TableSchema;
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.data.value.ClickHouseBitmap;
import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue;
Expand Down Expand Up @@ -377,4 +378,9 @@ public ClickHouseBitmap getClickHouseBitmap(String colName) {
public ClickHouseBitmap getClickHouseBitmap(int index) {
return reader.readValue(index);
}

@Override
public TableSchema getSchema() {
return reader.getSchema();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.clickhouse.client.api.query.GenericRecord;
import com.clickhouse.client.api.query.NullValueException;
import com.clickhouse.data.ClickHouseColumn;
import com.clickhouse.data.value.ClickHouseArrayValue;
import com.clickhouse.data.value.ClickHouseBitmap;
import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue;
import com.clickhouse.data.value.ClickHouseGeoPointValue;
Expand All @@ -23,17 +22,14 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.function.Function;

public class MapBackedRecord implements GenericRecord {

private final Map<String, Object> record;

private TableSchema schema;
private final TableSchema schema;

private Map[] columnConverters;

Expand Down Expand Up @@ -513,6 +509,11 @@ public ClickHouseBitmap getClickHouseBitmap(int index) {
return readValue(index);
}

@Override
public TableSchema getSchema() {
return this.schema;
}

@Override
public Object getObject(String colName) {
return readValue(colName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.clickhouse.client.api.query;

import com.clickhouse.data.value.ClickHouseBitmap;
import com.clickhouse.data.value.ClickHouseGeoMultiPolygonValue;
import com.clickhouse.data.value.ClickHouseGeoPointValue;
import com.clickhouse.data.value.ClickHouseGeoPolygonValue;
import com.clickhouse.data.value.ClickHouseGeoRingValue;
import com.clickhouse.client.api.metadata.TableSchema;
import com.clickhouse.data.ClickHouseColumn;
import com.clickhouse.data.value.*;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;

public interface GenericRecord {

Expand Down Expand Up @@ -500,4 +496,17 @@ public interface GenericRecord {
ClickHouseBitmap getClickHouseBitmap(String colName);

ClickHouseBitmap getClickHouseBitmap(int index);

TableSchema getSchema();

/**
* Returns all values of this record in Map.
*
* @return a Map of column names and values.
*/
default Map<String, Object> getAll() {
return this.getSchema().getColumns().stream().collect(Collectors.toMap(
ClickHouseColumn::getColumnName,
column -> this.getObject(column.getColumnName())));
}
}

0 comments on commit bd363cf

Please sign in to comment.