Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
212e1bb
Fasten listing tables in BigQuery connector
ebyhr Apr 18, 2021
f652531
Fix Join optimization rule
kasiafi Apr 18, 2021
76d585b
Add recommendations around language injection
ksobolew Apr 9, 2021
ebe0db7
Update testcontainers to 1.15.3
wendigo Apr 17, 2021
231853b
Enhance view owner validation
sopel39 Apr 7, 2021
60681db
Revert "Enhance view owner validation"
sopel39 Apr 19, 2021
f4dcf75
Enhance view owner validation
sopel39 Apr 7, 2021
269e9de
Add support for CREATE and DROP SCHEMA in BigQuery
ebyhr Apr 9, 2021
0bbc673
Remove unsed supportsMetadataDelete in HiveMetadata
electrum Apr 16, 2021
a9478d0
Use ACID semantics for whole partition deletes
electrum Apr 16, 2021
2455684
Simplify condition
wendigo Apr 19, 2021
208c9fd
Support Hive UPDATE with original files
Apr 16, 2021
6476c13
Fix ActiveCount metric name in JMX documentation
zhuhw Aug 20, 2020
b1af688
Encapsulate subquery analysis
martint Apr 9, 2021
52a84f0
Factor out join planning
martint Apr 9, 2021
c682a1d
Fix NPE when reading empty timestamp in Cassandra
ebyhr Apr 10, 2021
c6111d2
Fix oracle incorrect char padding
brandboat Jan 27, 2021
b9e0279
Convert oracle char unicode tests to SqlDataTypeTest
brandboat Jan 27, 2021
c903ac0
Speed up varcharToCharSaturatedFloorCast
Apr 14, 2021
1cb9b19
Add Connector#getMaterializedViewProperties
raunaqmorarka Apr 16, 2021
3504fcc
Use MaterializedViewPropertyManager in CreateMaterializedViewTask
raunaqmorarka Apr 16, 2021
e1262b2
Show properties in CREATE MATERIALIZED VIEW
raunaqmorarka Apr 16, 2021
db60c21
Add system.metadata.materialized_view_properties
raunaqmorarka Apr 16, 2021
43ee865
Add getMaterializedViewProperties to hive
raunaqmorarka Apr 16, 2021
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
13 changes: 13 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ Enable errorprone ([Error Prone Installation#IDEA](https://errorprone.info/docs/
- In ``Java Compiler`` tab, select ``Javac with error-prone`` as the compiler,
- Update ``Additional command line parameters`` with ``-XepExcludedPaths:.*/target/generated-(|test-)sources/.* -XepDisableAllChecks -Xep:MissingOverride:ERROR ......`` (for current recommended list of command line parameters, see the top level ``pom.xml``, the definition of the ``errorprone-compiler`` profile.

### Language injection in IDE

In order to enable language injection inside Intellij IDEA, some code elements can be annotated with the `@org.intellij.lang.annotations.Language` annotation. To make it useful, we recommend:

- Set the project-wide SQL dialect in ``Languages & Frameworks | SQL Dialects`` - "Generic SQL" is a decent choice here,
- Disable inspection ``SQL | No data source configured``,
- Optionally disable inspection ``Language injection | Language mismatch``.

Even if the IDE does not support language injection this annotation is useful for documenting the API's intent. Considering the above, we recommend annotating with `@Language`:

- All API parameters which are expecting to take a `String` containing an SQL statement (or any other language, like regular expressions),
- Local variables which otherwise would not be properly recognized by IDE for language injection.

## Building the Web UI

The Trino Web UI is composed of several React components and is written in JSX and ES6. This source code is compiled and packaged into browser-compatible Javascript, which is then checked in to the Trino source code (in the `dist` folder). You must have [Node.js](https://nodejs.org/en/download/) and [Yarn](https://yarnpkg.com/en/) installed to execute these commands. To update this folder after making changes, simply run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ private synchronized void addConnectorInternal(MaterializedConnector connector)
.ifPresent(accessControl -> accessControlManager.addCatalogAccessControl(catalogName, accessControl));

metadataManager.getTablePropertyManager().addProperties(catalogName, connector.getTableProperties());
metadataManager.getMaterializedViewPropertyManager().addProperties(catalogName, connector.getMaterializedViewProperties());
metadataManager.getColumnPropertyManager().addProperties(catalogName, connector.getColumnProperties());
metadataManager.getSchemaPropertyManager().addProperties(catalogName, connector.getSchemaProperties());
metadataManager.getAnalyzePropertyManager().addProperties(catalogName, connector.getAnalyzeProperties());
Expand Down Expand Up @@ -328,6 +329,7 @@ private synchronized void removeConnectorInternal(CatalogName catalogName)
metadataManager.getProcedureRegistry().removeProcedures(catalogName);
accessControlManager.removeCatalogAccessControl(catalogName);
metadataManager.getTablePropertyManager().removeProperties(catalogName);
metadataManager.getMaterializedViewPropertyManager().removeProperties(catalogName);
metadataManager.getColumnPropertyManager().removeProperties(catalogName);
metadataManager.getSchemaPropertyManager().removeProperties(catalogName);
metadataManager.getAnalyzePropertyManager().removeProperties(catalogName);
Expand Down Expand Up @@ -403,6 +405,7 @@ private static class MaterializedConnector
private final List<EventListener> eventListeners;
private final List<PropertyMetadata<?>> sessionProperties;
private final List<PropertyMetadata<?>> tableProperties;
private final List<PropertyMetadata<?>> materializedViewProperties;
private final List<PropertyMetadata<?>> schemaProperties;
private final List<PropertyMetadata<?>> columnProperties;
private final List<PropertyMetadata<?>> analyzeProperties;
Expand Down Expand Up @@ -493,6 +496,10 @@ public MaterializedConnector(CatalogName catalogName, Connector connector)
requireNonNull(tableProperties, format("Connector '%s' returned a null table properties set", catalogName));
this.tableProperties = ImmutableList.copyOf(tableProperties);

List<PropertyMetadata<?>> materializedViewProperties = connector.getMaterializedViewProperties();
requireNonNull(materializedViewProperties, format("Connector '%s' returned a null materialized view properties set", catalogName));
this.materializedViewProperties = ImmutableList.copyOf(materializedViewProperties);

List<PropertyMetadata<?>> schemaProperties = connector.getSchemaProperties();
requireNonNull(schemaProperties, format("Connector '%s' returned a null schema properties set", catalogName));
this.schemaProperties = ImmutableList.copyOf(schemaProperties);
Expand Down Expand Up @@ -571,6 +578,11 @@ public List<PropertyMetadata<?>> getTableProperties()
return tableProperties;
}

public List<PropertyMetadata<?>> getMaterializedViewProperties()
{
return materializedViewProperties;
}

public List<PropertyMetadata<?>> getColumnProperties()
{
return columnProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.connector.system;

import io.trino.metadata.Metadata;
import io.trino.transaction.TransactionManager;

import javax.inject.Inject;

public class MaterializedViewPropertiesSystemTable
extends AbstractPropertiesSystemTable
{
@Inject
public MaterializedViewPropertiesSystemTable(TransactionManager transactionManager, Metadata metadata)
{
super("materialized_view_properties", transactionManager, () -> metadata.getMaterializedViewPropertyManager().getAllProperties());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void configure(Binder binder)
globalTableBinder.addBinding().to(TableCommentSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(SchemaPropertiesSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(TablePropertiesSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(MaterializedViewPropertiesSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(ColumnPropertiesSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(AnalyzePropertiesSystemTable.class).in(Scopes.SINGLETON);
globalTableBinder.addBinding().to(TransactionsSystemTable.class).in(Scopes.SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ListenableFuture<?> execute(
.orElseThrow(() -> new TrinoException(NOT_FOUND, "Catalog does not exist: " + name.getCatalogName()));

Map<String, Expression> sqlProperties = mapFromProperties(statement.getProperties());
Map<String, Object> properties = metadata.getTablePropertyManager().getProperties(
Map<String, Object> properties = metadata.getMaterializedViewPropertyManager().getProperties(
catalogName,
name.getCatalogName(),
sqlProperties,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.trino.metadata;

import static io.trino.spi.StandardErrorCode.INVALID_MATERIALIZED_VIEW_PROPERTY;

public class MaterializedViewPropertyManager
extends AbstractPropertyManager
{
public MaterializedViewPropertyManager()
{
super("materialized view", INVALID_MATERIALIZED_VIEW_PROPERTY);
}
}
2 changes: 2 additions & 0 deletions core/trino-main/src/main/java/io/trino/metadata/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ default ResolvedFunction getCoercion(Type fromType, Type toType)

TablePropertyManager getTablePropertyManager();

MaterializedViewPropertyManager getMaterializedViewPropertyManager();

ColumnPropertyManager getColumnPropertyManager();

AnalyzePropertyManager getAnalyzePropertyManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public final class MetadataManager
private final SessionPropertyManager sessionPropertyManager;
private final SchemaPropertyManager schemaPropertyManager;
private final TablePropertyManager tablePropertyManager;
private final MaterializedViewPropertyManager materializedViewPropertyManager;
private final ColumnPropertyManager columnPropertyManager;
private final AnalyzePropertyManager analyzePropertyManager;
private final TransactionManager transactionManager;
Expand All @@ -214,6 +215,7 @@ public MetadataManager(
SessionPropertyManager sessionPropertyManager,
SchemaPropertyManager schemaPropertyManager,
TablePropertyManager tablePropertyManager,
MaterializedViewPropertyManager materializedViewPropertyManager,
ColumnPropertyManager columnPropertyManager,
AnalyzePropertyManager analyzePropertyManager,
TransactionManager transactionManager,
Expand All @@ -230,6 +232,7 @@ public MetadataManager(
this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null");
this.schemaPropertyManager = requireNonNull(schemaPropertyManager, "schemaPropertyManager is null");
this.tablePropertyManager = requireNonNull(tablePropertyManager, "tablePropertyManager is null");
this.materializedViewPropertyManager = requireNonNull(materializedViewPropertyManager, "materializedViewPropertyManager is null");
this.columnPropertyManager = requireNonNull(columnPropertyManager, "columnPropertyManager is null");
this.analyzePropertyManager = requireNonNull(analyzePropertyManager, "analyzePropertyManager is null");
this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
Expand Down Expand Up @@ -302,6 +305,7 @@ public static MetadataManager createTestMetadataManager(TransactionManager trans
new SessionPropertyManager(),
new SchemaPropertyManager(),
new TablePropertyManager(),
new MaterializedViewPropertyManager(),
new ColumnPropertyManager(),
new AnalyzePropertyManager(),
transactionManager,
Expand Down Expand Up @@ -2242,6 +2246,12 @@ public TablePropertyManager getTablePropertyManager()
return tablePropertyManager;
}

@Override
public MaterializedViewPropertyManager getMaterializedViewPropertyManager()
{
return materializedViewPropertyManager;
}

@Override
public ColumnPropertyManager getColumnPropertyManager()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.trino.operator.scalar;

import com.google.common.collect.ImmutableList;
import io.airlift.slice.Slice;
import io.airlift.slice.SliceUtf8;
import io.airlift.slice.Slices;
Expand All @@ -22,20 +21,17 @@
import io.trino.spi.function.OperatorType;
import io.trino.spi.function.ScalarOperator;
import io.trino.spi.function.SqlType;

import java.util.ArrayList;
import java.util.List;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;

import static com.google.common.base.Verify.verify;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.airlift.slice.SliceUtf8.getCodePointAt;
import static io.airlift.slice.SliceUtf8.lengthOfCodePoint;
import static io.airlift.slice.SliceUtf8.setCodePointAt;
import static io.trino.spi.type.Chars.padSpaces;
import static io.trino.spi.type.Chars.truncateToLengthAndTrimSpaces;
import static io.trino.spi.type.Varchars.truncateToLength;
import static java.lang.Math.toIntExact;
import static java.util.Collections.nCopies;

public final class CharacterStringCasts
{
Expand Down Expand Up @@ -92,66 +88,67 @@ public static Slice charToVarcharCast(@LiteralParameter("x") Long x, @LiteralPar
@LiteralParameters({"x", "y"})
public static Slice varcharToCharSaturatedFloorCast(@LiteralParameter("y") long y, @SqlType("varchar(x)") Slice slice)
{
List<Integer> codePoints = new ArrayList<>(toCodePoints(slice));
IntList codePoints = toCodePoints(slice);

// if Varchar(x) value length (including spaces) is greater than y, we can just truncate it
if (codePoints.size() >= y) {
// char(y) slice representation doesn't contain trailing spaces
codePoints = trimTrailing(codePoints, ' ');
List<Integer> codePointsTruncated = codePoints.stream()
.limit(y)
.collect(toImmutableList());
return codePointsToSliceUtf8(codePointsTruncated);
codePoints.size(Math.min(toIntExact(y), codePoints.size()));
trimTrailing(codePoints, ' ');
return codePointsToSliceUtf8(codePoints);
}

/*
* Value length is smaller than same-represented char(y) value because input varchar has length lower than y.
* We decrement last character in input (in fact, we decrement last non-zero character) and pad the value with
* max code point up to y characters.
*/
codePoints = trimTrailing(codePoints, '\0');
trimTrailing(codePoints, '\0');

if (codePoints.isEmpty()) {
// No non-zero characters in input and input is shorter than y. Input value is smaller than any char(4) casted back to varchar, so we return the smallest char(4) possible
return codePointsToSliceUtf8(nCopies(toIntExact(y), (int) '\0'));
return Slices.allocate(toIntExact(y));
}

codePoints = new ArrayList<>(codePoints);
codePoints.set(codePoints.size() - 1, codePoints.get(codePoints.size() - 1) - 1);
codePoints.addAll(nCopies(toIntExact(y) - codePoints.size(), Character.MAX_CODE_POINT));
int toAdd = toIntExact(y) - codePoints.size();
for (int i = 0; i < toAdd; i++) {
codePoints.add(Character.MAX_CODE_POINT);
}

verify(codePoints.get(codePoints.size() - 1) != ' '); // no trailing spaces to trim
verify(codePoints.getInt(codePoints.size() - 1) != ' '); // no trailing spaces to trim

return codePointsToSliceUtf8(codePoints);
}

private static List<Integer> trimTrailing(List<Integer> codePoints, int codePointToTrim)
private static void trimTrailing(IntList codePoints, int codePointToTrim)
{
int endIndex = codePoints.size();
while (endIndex > 0 && codePoints.get(endIndex - 1) == codePointToTrim) {
endIndex--;
}
return ImmutableList.copyOf(codePoints.subList(0, endIndex));
codePoints.size(endIndex);
}

private static List<Integer> toCodePoints(Slice slice)
private static IntList toCodePoints(Slice slice)
{
ImmutableList.Builder<Integer> codePoints = ImmutableList.builder();
IntList codePoints = new IntArrayList(slice.length());
for (int offset = 0; offset < slice.length(); ) {
int codePoint = getCodePointAt(slice, offset);
offset += lengthOfCodePoint(slice, offset);
codePoints.add(codePoint);
}
return codePoints.build();
return codePoints;
}

public static Slice codePointsToSliceUtf8(List<Integer> codePoints)
public static Slice codePointsToSliceUtf8(IntList codePoints)
{
int length = codePoints.stream()
.mapToInt(SliceUtf8::lengthOfCodePoint)
.sum();
int bufferLength = 0;
for (int codePoint : codePoints) {
bufferLength += SliceUtf8.lengthOfCodePoint(codePoint);
}

Slice result = Slices.wrappedBuffer(new byte[length]);
Slice result = Slices.wrappedBuffer(new byte[bufferLength]);
int offset = 0;
for (int codePoint : codePoints) {
setCodePointAt(codePoint, result, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import io.trino.metadata.ForNodeManager;
import io.trino.metadata.HandleJsonModule;
import io.trino.metadata.InternalNodeManager;
import io.trino.metadata.MaterializedViewPropertyManager;
import io.trino.metadata.Metadata;
import io.trino.metadata.MetadataManager;
import io.trino.metadata.SchemaPropertyManager;
Expand Down Expand Up @@ -222,6 +223,9 @@ protected void setup(Binder binder)
// table properties
binder.bind(TablePropertyManager.class).in(Scopes.SINGLETON);

// materialized view properties
binder.bind(MaterializedViewPropertyManager.class).in(Scopes.SINGLETON);

// column properties
binder.bind(ColumnPropertyManager.class).in(Scopes.SINGLETON);

Expand Down
Loading