Skip to content

Commit

Permalink
Add forConnectorId method to ConnectorSession
Browse files Browse the repository at this point in the history
Add a method forConnectorId to ConnectorSession to allow converting
ConnectorSession of one connector to a ConnectorSession for another
connector.
  • Loading branch information
rschlussel committed Feb 18, 2025
1 parent d6b494a commit 4435387
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ public RuntimeStats getRuntimeStats()
{
return session.getRuntimeStats();
}

@Override
public ConnectorSession forConnectorId(ConnectorId connectorId)
{
return this;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,10 @@ public RuntimeStats getRuntimeStats()
{
return session.getRuntimeStats();
}

@Override
public ConnectorSession forConnectorId(ConnectorId connectorId)
{
return new FullConnectorSession(session, identity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.facebook.presto.common.function.SqlFunctionProperties;
import com.facebook.presto.common.type.TimeZoneKey;
import com.facebook.presto.execution.QueryIdGenerator;
import com.facebook.presto.spi.ConnectorId;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.PrestoException;
import com.facebook.presto.spi.WarningCollector;
Expand Down Expand Up @@ -224,6 +225,26 @@ public RuntimeStats getRuntimeStats()
return new RuntimeStats();
}

@Override
public ConnectorSession forConnectorId(ConnectorId connectorId)
{
return new TestingConnectorSession(
sqlFunctionProperties.getSessionUser(),
identity,
source,
traceToken,
timeZoneKey,
locale,
startTime,
ImmutableList.copyOf(properties.values()),
propertyValues,
sqlFunctionProperties.isLegacyRowFieldOrdinalAccessEnabled(),
clientInfo,
clientTags,
schema,
sessionFunctions);
}

@Override
public String toString()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ default boolean isReadConstraints()
WarningCollector getWarningCollector();

RuntimeStats getRuntimeStats();

/**
* returns a ConnectorSession for a specific ConnectorId
* @return
*/
ConnectorSession forConnectorId(ConnectorId connectorId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ public RuntimeStats getRuntimeStats()
{
return new RuntimeStats();
}

@Override
public ConnectorSession forConnectorId(ConnectorId connectorId)
{
return this;
}
};

private TestingSession() {}
Expand Down

0 comments on commit 4435387

Please sign in to comment.