Search in sources :

Example 1 with PropertyMetadata

use of io.trino.spi.session.PropertyMetadata in project trino by trinodb.

the class PropertyMetadataUtil method durationProperty.

public static PropertyMetadata<Duration> durationProperty(String name, String description, Duration defaultValue, Consumer<Duration> validation, boolean hidden) {
    return new PropertyMetadata<>(name, description, VARCHAR, Duration.class, defaultValue, hidden, object -> {
        Duration value = Duration.valueOf((String) object);
        validation.accept(value);
        return value;
    }, Duration::toString);
}
Also used : PropertyMetadata(io.trino.spi.session.PropertyMetadata) Duration(io.airlift.units.Duration)

Example 2 with PropertyMetadata

use of io.trino.spi.session.PropertyMetadata in project trino by trinodb.

the class TestRubixCaching method setup.

@BeforeClass
public void setup() throws IOException {
    cacheStoragePath = getStoragePath("/");
    config = new HdfsConfig();
    List<PropertyMetadata<?>> hiveSessionProperties = getHiveSessionProperties(new HiveConfig(), new RubixEnabledConfig().setCacheEnabled(true), new OrcReaderConfig()).getSessionProperties();
    context = new HdfsContext(TestingConnectorSession.builder().setPropertyMetadata(hiveSessionProperties).build());
    nonCachingFileSystem = getNonCachingFileSystem();
}
Also used : OrcReaderConfig(io.trino.plugin.hive.orc.OrcReaderConfig) HdfsConfig(io.trino.plugin.hive.HdfsConfig) PropertyMetadata(io.trino.spi.session.PropertyMetadata) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) HiveConfig(io.trino.plugin.hive.HiveConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with PropertyMetadata

use of io.trino.spi.session.PropertyMetadata in project trino by trinodb.

the class AbstractPropertiesSystemTable method cursor.

@Override
public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
    InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata);
    List<CatalogName> catalogNames = transactionManager.getCatalogs(transactionId).keySet().stream().sorted().map(CatalogName::new).collect(toImmutableList());
    for (CatalogName catalogName : catalogNames) {
        catalogProperties.apply(catalogName).stream().sorted(Comparator.comparing(PropertyMetadata::getName)).forEach(propertyMetadata -> table.addRow(catalogName.toString(), propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), propertyMetadata.getDescription()));
    }
    return table.build().cursor();
}
Also used : PropertyMetadata(io.trino.spi.session.PropertyMetadata) CatalogName(io.trino.connector.CatalogName) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) TransactionId(io.trino.transaction.TransactionId)

Example 4 with PropertyMetadata

use of io.trino.spi.session.PropertyMetadata in project trino by trinodb.

the class PropertyMetadataUtil method dataSizeProperty.

public static PropertyMetadata<DataSize> dataSizeProperty(String name, String description, DataSize defaultValue, Consumer<DataSize> validation, boolean hidden) {
    return new PropertyMetadata<>(name, description, VARCHAR, DataSize.class, defaultValue, hidden, object -> {
        DataSize value = DataSize.valueOf((String) object);
        validation.accept(value);
        return value;
    }, DataSize::toString);
}
Also used : DataSize(io.airlift.units.DataSize) PropertyMetadata(io.trino.spi.session.PropertyMetadata)

Example 5 with PropertyMetadata

use of io.trino.spi.session.PropertyMetadata in project trino by trinodb.

the class TableProceduresPropertyManager method getProperties.

public Map<String, Object> getProperties(CatalogName catalog, String procedureName, Map<String, Expression> sqlPropertyValues, Session session, PlannerContext plannerContext, AccessControl accessControl, Map<NodeRef<Parameter>, Expression> parameters) {
    Map<String, PropertyMetadata<?>> supportedProperties = connectorProperties.get(new Key(catalog, procedureName));
    if (supportedProperties == null) {
        throw new TrinoException(NOT_FOUND, format("Catalog '%s' table procedure '%s' property not found", catalog, procedureName));
    }
    Map<String, Optional<Object>> propertyValues = evaluateProperties(sqlPropertyValues.entrySet().stream().map(entry -> new Property(new Identifier(entry.getKey()), entry.getValue())).collect(toImmutableList()), session, plannerContext, accessControl, parameters, true, supportedProperties, INVALID_PROCEDURE_ARGUMENT, format("catalog '%s' table procedure '%s' property", catalog, procedureName));
    return propertyValues.entrySet().stream().filter(entry -> entry.getValue().isPresent()).collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));
}
Also used : PropertyUtil.evaluateProperties(io.trino.metadata.PropertyUtil.evaluateProperties) ConcurrentMap(java.util.concurrent.ConcurrentMap) INVALID_PROCEDURE_ARGUMENT(io.trino.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) CatalogName(io.trino.connector.CatalogName) NodeRef(io.trino.sql.tree.NodeRef) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Property(io.trino.sql.tree.Property) Identifier(io.trino.sql.tree.Identifier) NOT_FOUND(io.trino.spi.StandardErrorCode.NOT_FOUND) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) PropertyMetadata(io.trino.spi.session.PropertyMetadata) Maps(com.google.common.collect.Maps) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AccessControl(io.trino.security.AccessControl) Parameter(io.trino.sql.tree.Parameter) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) Identifier(io.trino.sql.tree.Identifier) Optional(java.util.Optional) PropertyMetadata(io.trino.spi.session.PropertyMetadata) TrinoException(io.trino.spi.TrinoException) Property(io.trino.sql.tree.Property)

Aggregations

PropertyMetadata (io.trino.spi.session.PropertyMetadata)7 CatalogName (io.trino.connector.CatalogName)3 Session (io.trino.Session)2 Optional (java.util.Optional)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Maps (com.google.common.collect.Maps)1 DataSize (io.airlift.units.DataSize)1 Duration (io.airlift.units.Duration)1 TPCH_NATION_DATA (io.trino.connector.MockConnectorEntities.TPCH_NATION_DATA)1 TPCH_NATION_SCHEMA (io.trino.connector.MockConnectorEntities.TPCH_NATION_SCHEMA)1 MockConnectorFactory (io.trino.connector.MockConnectorFactory)1 MockConnectorPlugin (io.trino.connector.MockConnectorPlugin)1 MockConnectorTableHandle (io.trino.connector.MockConnectorTableHandle)1 AbstractMockMetadata (io.trino.metadata.AbstractMockMetadata)1