Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New IR -- WIP #24466

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
120 changes: 120 additions & 0 deletions core/trino-grammar/src/main/antlr4/io/trino/grammar/newir/NewIr.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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.
*/

grammar NewIr;

tokens {
DELIMITER
}

program
: IR VERSION EQ version=INTEGER_VALUE
operation EOF
;

operation
: resultName=VALUE_NAME EQ operationName
'(' (argumentNames+=VALUE_NAME (',' argumentNames+=VALUE_NAME)*)? ')'
':' '(' (argumentTypes+=type (',' argumentTypes+=type)*)? ')'
'->' resultType=type
'(' (region (',' region)*)? ')'
('{' (attribute (',' attribute)*)? '}')? // does not roundtrip: we don't print empty attributes list // TODO test
;

region
: '{' block+ '}'
;

block
: BLOCK_NAME?
('(' blockParameter (',' blockParameter)* ')')?
operation+
;

blockParameter
: VALUE_NAME ':' type
;

attribute
: attributeName EQ STRING
;

identifier
: IDENTIFIER
| nonReserved
;

dialectName
: identifier
;

operationName
: (dialectName '.')? identifier
;

attributeName
: (dialectName '.')? identifier
;

type
: (dialectName '.')? STRING
;

nonReserved
: IR | VERSION
;

IR: 'IR';
VERSION: 'version';

EQ: '=';

STRING
: '"' ( ~'"' | '""' )* '"'
;

VALUE_NAME
: '%' PREFIXED_IDENTIFIER
;

BLOCK_NAME
: '^' PREFIXED_IDENTIFIER
;

INTEGER_VALUE
: DIGIT+
;

IDENTIFIER
: (LETTER | '_') (LETTER | DIGIT | '_')*
;

PREFIXED_IDENTIFIER
: (LETTER | DIGIT | '_')+
;

fragment DIGIT
: [0-9]
;

fragment LETTER
: [a-z] | [A-Z]
;

WS
: [ \r\n\t]+ -> channel(HIDDEN)
;

// Catch-all for anything we can't recognize.
UNRECOGNIZED: .;
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.ProvidesIntoSet;
import io.airlift.concurrent.BoundedExecutor;
import io.airlift.configuration.AbstractConfigurationAwareModule;
Expand Down Expand Up @@ -82,6 +83,7 @@
import io.trino.metadata.SystemFunctionBundle;
import io.trino.metadata.SystemSecurityMetadata;
import io.trino.metadata.TableFunctionRegistry;
import io.trino.metadata.TableHandle;
import io.trino.metadata.TableProceduresRegistry;
import io.trino.metadata.TypeRegistry;
import io.trino.operator.DirectExchangeClientConfig;
Expand Down Expand Up @@ -109,6 +111,9 @@
import io.trino.spi.VersionEmbedder;
import io.trino.spi.block.Block;
import io.trino.spi.block.BlockEncodingSerde;
import io.trino.spi.connector.ColumnHandle;
import io.trino.spi.predicate.NullableValue;
import io.trino.spi.predicate.TupleDomain;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeManager;
import io.trino.spi.type.TypeOperators;
Expand All @@ -131,17 +136,22 @@
import io.trino.sql.SqlEnvironmentConfig;
import io.trino.sql.analyzer.SessionTimeProvider;
import io.trino.sql.analyzer.StatementAnalyzerFactory;
import io.trino.sql.dialect.trino.TrinoAttributeRegistry;
import io.trino.sql.dialect.trino.TrinoDialect;
import io.trino.sql.gen.ExpressionCompiler;
import io.trino.sql.gen.JoinCompiler;
import io.trino.sql.gen.JoinFilterFunctionCompiler;
import io.trino.sql.gen.OrderingCompiler;
import io.trino.sql.gen.PageFunctionCompiler;
import io.trino.sql.gen.columnar.ColumnarFilterCompiler;
import io.trino.sql.newir.DialectRegistry;
import io.trino.sql.newir.FormatOptions;
import io.trino.sql.parser.SqlParser;
import io.trino.sql.planner.CompilerConfig;
import io.trino.sql.planner.LocalExecutionPlanner;
import io.trino.sql.planner.NodePartitioningManager;
import io.trino.sql.planner.OptimizerConfig;
import io.trino.sql.planner.PartitioningHandle;
import io.trino.sql.planner.RuleStatsRecorder;
import io.trino.sql.planner.Symbol;
import io.trino.sql.planner.SymbolKeyDeserializer;
Expand All @@ -157,6 +167,7 @@
import io.trino.util.EmbedVersion;
import io.trino.util.FinalizerService;

import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -425,6 +436,18 @@ protected void setup(Binder binder)
newSetBinder(binder, Type.class);
binder.bind(RegisterJsonPath2016Type.class).asEagerSingleton();

// new IR
jsonCodecBinder(binder).bindJsonCodec(TableHandle.class);
jsonCodecBinder(binder).bindJsonCodec(new TypeLiteral<List<ColumnHandle>>() {});
jsonCodecBinder(binder).bindJsonCodec(new TypeLiteral<TupleDomain<ColumnHandle>>() {});
jsonCodecBinder(binder).bindJsonCodec(PartitioningHandle.class);
jsonCodecBinder(binder).bindJsonCodec(NullableValue.class);
jsonCodecBinder(binder).bindJsonCodec(new TypeLiteral<NullableValue[]>() {});
binder.bind(TrinoAttributeRegistry.class).in(Scopes.SINGLETON);
binder.bind(TrinoDialect.class).in(Scopes.SINGLETON);
binder.bind(DialectRegistry.class).in(Scopes.SINGLETON);
binder.bind(FormatOptions.class).in(Scopes.SINGLETON);

// split manager
binder.bind(SplitManager.class).in(Scopes.SINGLETON);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.sql.dialect.ir;

import com.google.common.collect.ImmutableMap;
import io.trino.spi.TrinoException;
import io.trino.sql.newir.Dialect;
import io.trino.sql.newir.Operation.AttributeKey;
import io.trino.sql.newir.Type;

import java.util.Map;

import static io.trino.spi.StandardErrorCode.IR_ERROR;
import static java.lang.Boolean.TRUE;
import static java.lang.String.format;

public class IrDialect
extends Dialect
{
public static final String IR = "ir";
public static final IrDialect IR_DIALECT = new IrDialect();

public static final String TERMINAL = "terminal";

private IrDialect()
{
super(IR);
}

@Override
public String formatAttribute(String name, Object attribute)
{
if (!TERMINAL.equals(name) || !TRUE.equals(attribute)) {
throw new TrinoException(IR_ERROR, format("the ir dialect does not support attribute %s = %s", name, attribute));
}

return "true";
}

@Override
public Object parseAttribute(String name, String attribute)
{
if (!TERMINAL.equals(name) || !"true".equals(attribute)) {
throw new TrinoException(IR_ERROR, format("the ir dialect does not support attribute %s = %s", name, attribute));
}

return true;
}

@Override
public String formatType(Type type)
{
throw new UnsupportedOperationException("the ir dialect does not support any types");
}

@Override
public Type parseType(String type)
{
throw new UnsupportedOperationException("the ir dialect does not support any types");
}

public static void terminalOperation(ImmutableMap.Builder<AttributeKey, Object> builder)
{
builder.put(new AttributeKey(IR, TERMINAL), true);
}

public static Map<AttributeKey, Object> terminalOperation()
{
return ImmutableMap.of(new AttributeKey(IR, TERMINAL), true);
}
}
Loading