Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,16 @@
public abstract class ExternalTableDefinition extends TableDefinition {

static final Function<ExternalDataConfiguration, ExternalTableDefinition>
FROM_EXTERNAL_DATA_FUNCTION =
new Function<ExternalDataConfiguration, ExternalTableDefinition>() {
@Override
public ExternalTableDefinition apply(ExternalDataConfiguration pb) {
return ExternalTableDefinition.fromExternalDataConfiguration(pb);
}
};
FROM_EXTERNAL_DATA_FUNCTION = ExternalTableDefinition::fromExternalDataConfiguration;
static final Function<ExternalTableDefinition, ExternalDataConfiguration>
TO_EXTERNAL_DATA_FUNCTION =
new Function<ExternalTableDefinition, ExternalDataConfiguration>() {
@Override
public ExternalDataConfiguration apply(ExternalTableDefinition tableInfo) {
return tableInfo.toExternalDataConfigurationPb();
}
};
TO_EXTERNAL_DATA_FUNCTION = ExternalTableDefinition::toExternalDataConfigurationPb;

private static final long serialVersionUID = -5951580238459622025L;

public static final class SourceColumnMatch extends StringEnumValue {
private static final long serialVersionUID = 818920627219751207L;
private static final ApiFunction<String, SourceColumnMatch> CONSTRUCTOR =
new ApiFunction<String, SourceColumnMatch>() {
@Override
public SourceColumnMatch apply(String constant) {
return new SourceColumnMatch(constant);
}
};
SourceColumnMatch::new;

private static final StringEnumType<SourceColumnMatch> type =
new StringEnumType<SourceColumnMatch>(SourceColumnMatch.class, CONSTRUCTOR);
Expand Down Expand Up @@ -898,7 +881,7 @@ static ExternalTableDefinition fromExternalDataConfiguration(
builder.setTimeFormat(externalDataConfiguration.getTimeFormat());
}
if (externalDataConfiguration.getTimestampFormat() != null) {
builder.setTimestampFormat(externalDataConfiguration.getTimeFormat());
builder.setTimestampFormat(externalDataConfiguration.getTimestampFormat());
}
if (externalDataConfiguration.getCsvOptions() != null) {
if (externalDataConfiguration.getCsvOptions().getSourceColumnMatch() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ com.google.api.services.bigquery.model.IndexUnusedReason toPb() {
com.google.api.services.bigquery.model.IndexUnusedReason indexUnusedReason =
new com.google.api.services.bigquery.model.IndexUnusedReason();
if (getIndexName() != null) {
indexUnusedReason.setIndexName(indexUnusedReason.getIndexName());
indexUnusedReason.setIndexName(getIndexName());
}
if (getCode() != null) {
indexUnusedReason.setCode(indexUnusedReason.getCode());
indexUnusedReason.setCode(getCode());
}
if (getMessage() != null) {
indexUnusedReason.setMessage(indexUnusedReason.getMessage());
indexUnusedReason.setMessage(getMessage());
}
if (getBaseTableId() != null) {
indexUnusedReason.setBaseTable(getBaseTableId().toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ protected Builder(com.google.api.services.bigquery.model.JobStatistics statistic
if (statisticsPb.getScriptStatistics() != null) {
this.scriptStatistics = ScriptStatistics.fromPb(statisticsPb.getScriptStatistics());
}
if (reservationUsage != null) {
if (statisticsPb.getReservationUsage() != null) {
this.reservationUsage =
Lists.transform(statisticsPb.getReservationUsage(), ReservationUsage.FROM_PB_FUNCTION);
}
Expand Down Expand Up @@ -1692,6 +1692,11 @@ B setSessionInfo(SessionInfo sessionInfo) {
return self();
}

B setReservationUsage(List<ReservationUsage> reservationUsage) {
this.reservationUsage = reservationUsage;
return self();
}

abstract T build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@
* <li>Double: StandardSQLTypeName.FLOAT64
* <li>Float: StandardSQLTypeName.FLOAT64
* <li>BigDecimal: StandardSQLTypeName.NUMERIC
* <li>BigNumeric: StandardSQLTypeName.BIGNUMERIC
* <li>JSON: StandardSQLTypeName.JSON
* <li>INTERVAL: StandardSQLTypeName.INTERVAL
* <li>Date: StandardSQLTypeName.DATE
* <li>JsonObject: StandardSQLTypeName.JSON
* </ul>
*
* <p>No other types are supported through that entry point. The other types can be created by
Expand Down Expand Up @@ -424,13 +423,27 @@ public static QueryParameterValue struct(Map<String, QueryParameterValue> struct
.build();
}

/**
* Default instances created automatically by the static {@link #of(Object, Class)} method.
* Contains these mappings ONLY for natively supported types.
*
* <ul>
* <li>Boolean: StandardSQLTypeName.BOOL
* <li>String: StandardSQLTypeName.STRING
* <li>Integer: StandardSQLTypeName.INT64
* <li>Long: StandardSQLTypeName.INT64
* <li>Double: StandardSQLTypeName.FLOAT64
* <li>Float: StandardSQLTypeName.FLOAT64
* <li>BigDecimal: StandardSQLTypeName.NUMERIC
* <li>Date: StandardSQLTypeName.DATE
* <li>JsonObject: StandardSQLTypeName.JSON
* </ul>
*/
private static <T> StandardSQLTypeName classToType(Class<T> type) {
if (Boolean.class.isAssignableFrom(type)) {
return StandardSQLTypeName.BOOL;
} else if (String.class.isAssignableFrom(type)) {
return StandardSQLTypeName.STRING;
} else if (String.class.isAssignableFrom(type)) {
return StandardSQLTypeName.GEOGRAPHY;
} else if (Integer.class.isAssignableFrom(type)) {
return StandardSQLTypeName.INT64;
} else if (Long.class.isAssignableFrom(type)) {
Expand All @@ -443,8 +456,6 @@ private static <T> StandardSQLTypeName classToType(Class<T> type) {
return StandardSQLTypeName.NUMERIC;
} else if (Date.class.isAssignableFrom(type)) {
return StandardSQLTypeName.DATE;
} else if (String.class.isAssignableFrom(type)) {
return StandardSQLTypeName.JSON;
} else if (JsonObject.class.isAssignableFrom(type)) {
return StandardSQLTypeName.JSON;
}
Expand Down Expand Up @@ -487,9 +498,14 @@ private static <T> String valueToStringOrNull(T value, StandardSQLTypeName type)
case GEOGRAPHY:
return value.toString();
case JSON:
if (value instanceof String || value instanceof JsonObject) return value.toString();
if (value instanceof String || value instanceof JsonObject) {
return value.toString();
}
break;
case INTERVAL:
if (value instanceof String || value instanceof PeriodDuration) return value.toString();
if (value instanceof String || value instanceof PeriodDuration) {
return value.toString();
}
break;
case STRUCT:
throw new IllegalArgumentException("Cannot convert STRUCT to String value");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ void testToAndFromPb() {
ExternalTableDefinition.newBuilder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS).build();
compareExternalTableDefinition(
externalTableDefinition, ExternalTableDefinition.fromPb(externalTableDefinition.toPb()));
compareExternalTableDefinition(
EXTERNAL_TABLE_DEFINITION.toBuilder().setMaxStaleness(null).build(),
ExternalTableDefinition.fromExternalDataConfiguration(
EXTERNAL_TABLE_DEFINITION.toExternalDataConfigurationPb()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,27 @@ public class JobStatisticsTest {
private static final List<QueryStage> QUERY_PLAN = ImmutableList.of(QUERY_STAGE);
private static final Schema SCHEMA = Schema.of(Field.of("column", LegacySQLTypeName.DATETIME));
private static final String UNUSED_INDEX_USAGE_MODE = "UNUSED";
private static final IndexUnusedReason INDEX_UNUSED_REASON =
IndexUnusedReason.newBuilder()
.setIndexName("idx_search")
.setCode("BASE_TABLE_TOO_SMALL")
.setMessage("Base table is too small to use search index")
.setBaseTableId(DDL_TARGET_TABLE)
.build();
private static final SearchStats SEARCH_STATS =
SearchStats.newBuilder().setIndexUsageMode(UNUSED_INDEX_USAGE_MODE).build();
SearchStats.newBuilder()
.setIndexUsageMode(UNUSED_INDEX_USAGE_MODE)
.setIndexUnusedReasons(ImmutableList.of(INDEX_UNUSED_REASON))
.build();

private static final MetadataCacheStats METADATA_CACHE_STATS =
MetadataCacheStats.newBuilder()
.setTableMetadataCacheUsage(
ImmutableList.of(
TableMetadataCacheUsage.newBuilder().setExplanation("test explanation").build()))
.build();
private static final ReservationUsage RESERVATION_USAGE =
ReservationUsage.newBuilder().setName(NAME).setSlotMs(SLOTMS).build();

private static final QueryStatistics QUERY_STATISTICS =
QueryStatistics.newBuilder()
Expand Down Expand Up @@ -213,6 +225,7 @@ public class JobStatisticsTest {
.setSchema(SCHEMA)
.setSearchStats(SEARCH_STATS)
.setMetadataCacheStats(METADATA_CACHE_STATS)
.setReservationUsage(ImmutableList.of(RESERVATION_USAGE))
.build();
private static final QueryStatistics QUERY_STATISTICS_INCOMPLETE =
QueryStatistics.newBuilder()
Expand Down Expand Up @@ -262,8 +275,6 @@ public class JobStatisticsTest {
.setEvaluationKind(EVALUATIONKIND_TYPE_EXPRESSION)
.setStackFrames(ImmutableList.of(EXPRESSION_STACK_FRAME))
.build();
private static final ReservationUsage RESERVATION_USAGE =
ReservationUsage.newBuilder().setName(NAME).setSlotMs(SLOTMS).build();

private static final TransactionInfo TRANSACTION_INFO =
TransactionInfo.newbuilder().setTransactionId(TRANSACTION_ID).build();
Expand Down Expand Up @@ -460,8 +471,7 @@ private void compareQueryStatistics(QueryStatistics expected, QueryStatistics va
assertEquals(expected.getQueryPlan(), value.getQueryPlan());
assertEquals(expected.getReferencedTables(), value.getReferencedTables());
assertEquals(expected.getSchema(), value.getSchema());
assertEquals(
expected.getSearchStats().getIndexUsageMode(), value.getSearchStats().getIndexUsageMode());
assertEquals(expected.getSearchStats(), value.getSearchStats());
assertEquals(expected.getMetadataCacheStats(), value.getMetadataCacheStats());
assertEquals(expected.getStatementType(), value.getStatementType());
assertEquals(expected.getTimeline(), value.getTimeline());
Expand All @@ -479,6 +489,7 @@ private void compareStatistics(JobStatistics expected, JobStatistics value) {
assertEquals(expected.getNumChildJobs(), value.getNumChildJobs());
assertEquals(expected.getParentJobId(), value.getParentJobId());
assertEquals(expected.getScriptStatistics(), value.getScriptStatistics());
assertEquals(expected.getReservationUsage(), value.getReservationUsage());
assertEquals(expected.getTotalSlotMs(), value.getTotalSlotMs());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public void testJson() {
assertThat(value1.getArrayType()).isNull();
assertThat(value.getArrayValues()).isNull();
assertThat(value1.getArrayType()).isNull();
assertThrows(
IllegalArgumentException.class,
() -> QueryParameterValue.of(123, StandardSQLTypeName.JSON));
}

@Test
Expand All @@ -213,6 +216,9 @@ public void testInterval() {
assertThat(value.getArrayType()).isNull();
assertThat(value1.getArrayType()).isNull();
assertThat(value2.getArrayType()).isNull();
assertThrows(
IllegalArgumentException.class,
() -> QueryParameterValue.of(123, StandardSQLTypeName.INTERVAL));
}

@Test
Expand Down
Loading