Skip to content
Merged
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 @@ -126,6 +126,12 @@ Builder setFeatureColumns(List<StandardSQLField> featureColumnList) {
return this;
}

@Override
public Builder setEncryptionConfiguration(EncryptionConfiguration configuration) {
infoBuilder.setEncryptionConfiguration(configuration);
return this;
}

public Model build() {
return new Model(bigquery, infoBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Model apply(ModelInfo ModelInfo) {
private final ImmutableList<TrainingRun> trainingRunList;
private final ImmutableList<StandardSQLField> featureColumnList;
private final ImmutableList<StandardSQLField> labelColumnList;
private final EncryptionConfiguration encryptionConfiguration;

/** A builder for {@code ModelInfo} objects. */
public abstract static class Builder {
Expand Down Expand Up @@ -112,6 +113,8 @@ public abstract static class Builder {

abstract Builder setFeatureColumns(List<StandardSQLField> featureColumnList);

public abstract Builder setEncryptionConfiguration(EncryptionConfiguration configuration);

/** Creates a {@code ModelInfo} object. */
public abstract ModelInfo build();
}
Expand All @@ -130,6 +133,7 @@ static class BuilderImpl extends Builder {
private List<TrainingRun> trainingRunList = Collections.emptyList();
private List<StandardSQLField> labelColumnList = Collections.emptyList();
private List<StandardSQLField> featureColumnList = Collections.emptyList();
private EncryptionConfiguration encryptionConfiguration;

BuilderImpl() {}

Expand All @@ -145,6 +149,7 @@ static class BuilderImpl extends Builder {
this.trainingRunList = modelInfo.trainingRunList;
this.labelColumnList = modelInfo.labelColumnList;
this.featureColumnList = modelInfo.featureColumnList;
this.encryptionConfiguration = modelInfo.encryptionConfiguration;
}

BuilderImpl(Model modelPb) {
Expand All @@ -171,6 +176,10 @@ static class BuilderImpl extends Builder {
this.featureColumnList =
Lists.transform(modelPb.getFeatureColumns(), StandardSQLField.FROM_PB_FUNCTION);
}
if (modelPb.getEncryptionConfiguration() != null) {
this.encryptionConfiguration =
new EncryptionConfiguration.Builder(modelPb.getEncryptionConfiguration()).build();
}
}

@Override
Expand Down Expand Up @@ -245,6 +254,12 @@ Builder setFeatureColumns(List<StandardSQLField> featureColumnList) {
return this;
}

@Override
public Builder setEncryptionConfiguration(EncryptionConfiguration configuration) {
this.encryptionConfiguration = configuration;
return this;
}

@Override
public ModelInfo build() {
return new ModelInfo(this);
Expand All @@ -264,6 +279,7 @@ public ModelInfo build() {
this.trainingRunList = ImmutableList.copyOf(builder.trainingRunList);
this.labelColumnList = ImmutableList.copyOf(builder.labelColumnList);
this.featureColumnList = ImmutableList.copyOf(builder.featureColumnList);
this.encryptionConfiguration = builder.encryptionConfiguration;
}

/** Returns the hash of the model resource. */
Expand Down Expand Up @@ -332,6 +348,10 @@ public ImmutableList<StandardSQLField> getFeatureColumns() {
return featureColumnList;
}

public EncryptionConfiguration getEncryptionConfiguration() {
return encryptionConfiguration;
}

public Builder toBuilder() {
return new BuilderImpl(this);
}
Expand All @@ -351,6 +371,7 @@ public String toString() {
.add("trainingRuns", trainingRunList)
.add("labelColumns", labelColumnList)
.add("featureColumns", featureColumnList)
.add("encryptionConfiguration", encryptionConfiguration)
.toString();
}

Expand Down Expand Up @@ -403,6 +424,9 @@ Model toPb() {
modelPb.setFeatureColumns(
Lists.transform(featureColumnList, StandardSQLField.TO_PB_FUNCTION));
}
if (encryptionConfiguration != null) {
modelPb.setEncryptionConfiguration(encryptionConfiguration.toPb());
}
return modelPb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class ModelInfoTest {
private static final Long EXPIRATION_TIME = 30L;
private static final String DESCRIPTION = "description";
private static final String FRIENDLY_NAME = "friendlyname";
private static final EncryptionConfiguration MODEL_ENCRYPTION_CONFIGURATION =
EncryptionConfiguration.newBuilder().setKmsKeyName("KMS_KEY_1").build();

private static final TrainingOptions TRAINING_OPTIONS =
new TrainingOptions().setDataSplitColumn("foo").setEarlyStop(true).setLossType("bar");
Expand All @@ -49,6 +51,7 @@ public class ModelInfoTest {
.setDescription(DESCRIPTION)
.setFriendlyName(FRIENDLY_NAME)
.setTrainingRuns(TRAINING_RUN_LIST)
.setEncryptionConfiguration(MODEL_ENCRYPTION_CONFIGURATION)
.build();

@Test
Expand All @@ -71,6 +74,7 @@ public void testBuilder() {
assertEquals(DESCRIPTION, MODEL_INFO.getDescription());
assertEquals(FRIENDLY_NAME, MODEL_INFO.getFriendlyName());
assertEquals(TRAINING_OPTIONS, MODEL_INFO.getTrainingRuns().get(0).getTrainingOptions());
assertEquals(MODEL_ENCRYPTION_CONFIGURATION, MODEL_INFO.getEncryptionConfiguration());
}

@Test
Expand All @@ -83,6 +87,7 @@ public void testOf() {
assertNull(modelInfo.getExpirationTime());
assertNull(modelInfo.getDescription());
assertNull(modelInfo.getFriendlyName());
assertNull(modelInfo.getEncryptionConfiguration());
assertEquals(modelInfo.getTrainingRuns().isEmpty(), true);
assertEquals(modelInfo.getLabelColumns().isEmpty(), true);
assertEquals(modelInfo.getFeatureColumns().isEmpty(), true);
Expand Down Expand Up @@ -112,5 +117,6 @@ private void compareModelInfo(ModelInfo expected, ModelInfo value) {
assertEquals(expected.getTrainingRuns(), value.getTrainingRuns());
assertEquals(expected.getLabelColumns(), value.getLabelColumns());
assertEquals(expected.getFeatureColumns(), value.getFeatureColumns());
assertEquals(expected.getEncryptionConfiguration(), value.getEncryptionConfiguration());
}
}